We study a Hamilton-Jacobi partial differential equation, arizing in optimal control problem for an affine nonlinear singularly perturbed system. This equation is solvable: iff there exists a special invariant manifold of the corresponding Hamiltonian system. We obtain exact slow-fast decomposition of the Hamiltonian system and of the special invariant manifold into the slow and the fast ones. We get sufficient conditions for the solvability of the HamiltonJacobi equation in terms of the reduced-order slow submanifold, or in the hyperbolic case, in terms of a reduced-order slow Riccati equation. On the basis of this decomposition we construct asymptotic expansions of the optimal state-feedback, optimal trajectory and optimal open-loop control in the powers of a small parameter.