Necessary and sufficient conditions ensuring the existence of a solution to the viability problems for differential inclusions of second order have been studied in recent years. However optimization problems of second-order differential inclusions with viable constraints considered in this paper have not been examined yet. In the present paper we derive the optimality conditions for the Mayer problem discrete and differential inclusions with viable constraints. Applying necessary and sufficient conditions to problems with geometric constraints, optimality conditions for second order discrete inclusions are formulated. Using Locally Adjoint Mapping we conceive necessary and sufficient conditions for the optimality of the discrete approximation problem. Passing to the limit, sufficient conditions to the optimal problem are established.