Safety and stability control of energy storage grid connection