The increasing penetration of distributed generators may harm power system and its control and operations. The microgrid offers a better solution for the issues in grid operation. Undergraduate electrical engineering and postgraduate power system and power electronics students need to understand the working of microgrid with renewable energy resources along with the optimization and scheduling of power quality custom power devices. To cater better understanding of the microgrid with renewable resources, wind, solar, distributed generators, distributed energy storage devices, DSTATCOM, and plug-in electric vehicle charging load are included in this work presented. In this paper, multiobjective optimization for the operation of microgrid to account for uncertainties in a stochastic energy resources management system is considered. Nonlinear constraint optimization to reduce the running cost, losses, and voltage variations is focused for the optimization. Loss sensitivity analysis is used to find the location wind, solar, distributed generators, distributed energy storage devices, and DSTATCOM. Firefly algorithm is used to optimize the size of distributed generators and DSTATCOM. Optimization reduced the loss, power taken from the grid and improves the voltages in the system. This paper is self-explanatory to the undergraduate and postgraduate students to understand the power flow analysis of microgrid with hybrid renewable energies and optimization technique.