An energy storage system including a photovoltaic system and a battery system and connected with a power grid, the energy storage system comprising: a power conversion system configured to be connected with the power grid and connectable to the photovoltaic system and the battery system; a first ground fault detector (GFDI) connected to the ground and configured to detect a ground fault of the photovoltaic system; a first switch connected to the photovoltaic system and a direct current link of the power conversion system; a second switch connected to the battery system and the DC link of the power conversion system; a third switch positioned between the first switch and the photovoltaic system; a controller configured to control ground structures of the photovoltaic system and the battery system by controlling the first switch, the second switch and the third switch based on a state of the photovoltaic system and a state of the battery system to set the ground structure into a floating ground structure or a grounding ground structure, the state of the battery system being a charging state, a resting state after charging, a discharging state or a resting state after discharging, the state of the photovoltaic system being a state in which the photovoltaic system generates power or a state in which the photovoltaic system does not generate power, wherein the first ground fault detector (GFDI) is connectable to the first switch and the photovoltaic system through the third switch, wherein the controller is configured to set the ground structure of the battery system into a floating ground structure when the battery system is in a charging state, a discharging state or a resting state after discharging, and configured to set the ground structure of the photovoltaic system into a grounding ground structure when the battery system is in a discharging state or a resting state after discharging and into a floating ground structure when the battery system is in a charging state. a power conversion system configured to be connected with the power grid and connectable to the photovoltaic system and the battery system; a first ground fault detector (GFDI) connected to the ground and configured to detect a ground fault of the photovoltaic system; a first switch connected to the photovoltaic system and a direct current link of the power conversion system; a second switch connected to the battery system and the DC link of the power conversion system; a third switch positioned between the first switch and the photovoltaic system; a controller configured to control ground structures of the photovoltaic system and the battery system by controlling the first switch, the second switch and the third switch based on a state of the photovoltaic system and a state of the battery system to set the ground structure into a floating ground structure or a grounding ground structure, the state of the battery system being a charging state, a resting state after charging, a discharging state or a resting state after discharging, the state of the photovoltaic system being a state in which the photovoltaic system generates power or a state in which the photovoltaic system does not generate power, wherein the first ground fault detector (GFDI) is connectable to the first switch and the photovoltaic system through the third switch, wherein the controller is configured to set the ground structure of the battery system into a floating ground structure when the battery system is in a charging state, a discharging state or a resting state after discharging, and configured to set the ground structure of the photovoltaic system into a grounding ground structure when the battery system is in a discharging state or a resting state after discharging and into a floating ground structure when the battery system is in a charging state.