For an optimal control problem with a linear differential equation in Hilbert space and quadratic criteria necessary and sufficient conditions of control functions optimality and approximate formulas of the expansions of these functions in eigenfunctions of the control system operator have been obtained.