With the increasing proportion of renewable energy in microgrids (MGs), its stochastic fluctuation of output power has posed challenges to system safety and operation, especially frequency stability. Virtual synchronous generator (VSG) technology, as one effective method, was used to smoothen frequency fluctuation and improve the system's dynamic performance, which can simulate the inertia and damping of the traditional synchronous generator. This study outlines the integration of VSG-controlled energy storage systems (ESSs) and traditional synchronous generators so they jointly participate in secondary frequency regulation in an independent MG. Firstly, a new uncertain state-space model for secondary frequency control is established, considering the measurement noises and modelling error. Then, an improved linear quadratic Gaussian (LQG) controller is designed based on stochastic optimal control theory, in which the dynamic performance index weighting matrices are optimized by combining loop transfer recovery (LTR) technology and the distribution estimation algorithm. On the issue of secondary frequency devices' output power allocation, the dynamic participation factors based on the ESS's current state of charge (SOC) are proposed to prevent the batteries' overcharging and overdischarging problems. The energy storage devices' service life can be prolonged and OPEX (operational expenditure) decreased. Multiple experimental scenarios with real parameters of MGs are employed to evaluate the performance of the proposed algorithm. The results show that, compared with the lead-compensated-proportional-integral-derivative (LC-PID) control and robust µ-control algorithms, the proposed stochastic optimal control method has a faster dynamic response and is more robust, and the fluctuations from renewable energy and power loads can be smoothened more effectively.