Modern (micro) grids host inverter-based generation units for utilizing renewable and sustainable energy resources. Due to the lack of physical inertia and, thus, the low inertia level of inverter-interfaced energy resources, the frequency dynamic is adversely affected, which critically impacts the stability of autonomous microgrids. The idea of virtual inertia control (VIC), assisted by battery energy storage systems (BESSs), has been presented to improve the frequency dynamic in islanded microgrids. This study presents the PD-FOPID cascaded controller for the BESS, a unique method for enhancing the performance of VIC in islanded microgrids. Using the firefly algorithm (FA), the settings of this controller are optimally tuned. This approach is robust to disruptions due to uncertainties in islanded microgrids. In several scenarios, the performance of the suggested approach is compared with those of other control techniques, such as VIC based on an MPC controller, VIC based on a robust H-infinite controller, adaptive VIC, and VIC based on an optimized PI controller. The simulation results in MATLAB show that the suggested methodology in the area of VIC is better than previous methods.