Characterization of optimal plans for stochastic dynamic programs