In this paper, we consider optimization Dirichlet and Neumann problems for differential inclusions in which the right-hand sides are governed by multivalued function (mapping), which depends not only of the unknown functions, but also on the first partial derivatives of these functions. This generalization is very important, and the results obtained cannot be deduced from the results of the first author considered earlier. Formulations of sufficient conditions are based on the discretization idea of the continuous problem and equivalence theorems. Thus in the form of the Euler-Lagrange inclusion, sufficient optimality conditions are derived; for this, locally adjoint mappings are used. In general, we establish necessary and sufficient conditions for the so-called discrete approximation problem on a uniform grid. These conditions take an intermediate place between discrete and continuous problems. The results are generalized to the multidimensional case with a second-order elliptic operator.