Penetration of renewable energy resources in modern power systems has increased rapidly. The integration of different renewable and nonrenewable resources for the purpose of electricity generation is referred to as Distributed Generation (DG) units. The penetration of DG units gave birth to the concept of power microgrid. Power inverters play a major role in the integration of DGs in the power system. Control and stability analysis of microgrids in power systems is a challenging task for the control community. Dynamic microgrid modeling demands knowledge of fundamental engineering laws to detailed theoretical analysis. To model the dynamic behavior of the power microgrid, a basic understanding of the power converter operation modes and their control schemes is necessary. The main microgrid modeling components are power converters, power lines, transformers, protection systems, load, and faults. In this paper, preliminary concepts of power systems along with graph theoretic approach are used to develop the model of the microgrid and main grid networks. A mathematical model of a power microgrid in islanded mode, as well as the grid-connected mode, is developed and comprises of generation sources, power inverter interface, protection mechanism, load, faults, and transmission lines. The developed mathematical model can be used to address the stability issues as well as resilience in the power networks for complete system analysis. To validate the mathematical model, a renewable energy-based main grid and microgrid model is simulated. The graphical result of simulated model presents the generation and load curves.