Characterization of optimal controls