Abstract: This paper investigates the control performance of a physical configuration of a microgrid (MG), integrated with photovoltaic (PV) arrays, battery energy storage systems (BESSs), and variable loads. The main purpose is to achieve cooperative optimal control under both grid-connected and islanded modes for the MG. For the grid-connected mode, a voltage source inverter (VSI) based on swoop control is used to control the MG connection to the grid even if PV arrays are under partially shading conditions (PSC). Then, for the islanded mode, the paper analyzes the model of the PV unit and BESS unit detailed from the small signal point of view and designs the suitable control strategy for them. Finally, the whole MG system combines the droop control and the main/slave control to stabilize the DC bus line voltage and frequency. Both simulation and experimental results confirm that the proposed method can achieve cooperative control of the MG system in both grid-connected and islanded mode.Keywords: Grid-Connected Mode Mode, Microgrid Control, Distributed Generation, Energy Management, , Energy Storage, Frequency Control, Microgrid, Power System, Voltage Control