Optimal power flow (OPF) analysis enables the in-depth study and examination of islanded microgrid design and operation. The development of the analysis framework, including modeling, formulating, and selecting effective OPF solvers, however, is a nontrivial task. As a result, this paper presents a tutorial on an OPF modeling framework, offering a mathematical model that can be readily implemented using established open-source software tools such as OpenDSS, Pyomo, and IPOPT. The framework is versatile, capable of representing single-phase and unbalanced three-phase islanded microgrids. Various inverter models, such as those of grid forming and following equipped with their operating characteristics, can be incorporated. The efficacy of the proposed framework is demonstrated in studying the OPF of single-phase and three-phase microgrids.