Microgrid (MG) has gained significant attention because of the growing demand for electricity and the energy recession. MG has experienced notable advancements in both concept and technology, with a particular emphasis on automating the distribution process and enhancing the incorporation of alternative resources. This study addresses the energy management (EM) of an MG through the integration of distributed generation (DG), battery storage systems (BSS), and plug-in hybrid electric vehicles (PHEVs). Operational cost minimization of an MG connected to the utility by optimizing the battery capacity and efficiently managing energy within the MG is the primary objective of this research article. A proposed smart charging technique is introduced to regulate the demand for PHEV charging at both domestic and public charging stations. The simulation analysis is performed for an entire day, taking into account the sporadic nature of PHEV charging, load profiles, outputs of renewable energy sources, and fluctuations in energy prices. This complex nonlinear optimization problem of EM in an MG is addressed by employing the slime mould algorithm (SMA), which is a metaheuristic-based sporadic optimizer. The efficacy of SMA can be assessed by comparing its outcomes with those of alternative optimization methods.