Modeling Control Estimation and Optimization for Microgrids