Stochastic Optimization for Distributed Energy Resources in Smart Grids