With the increasing prominence of renewable energy sources providing flexibility to the power grid, there is a growing recognition of the need to expand virtual Energy Storage Systems (ESS) to replace traditional ESS, which faces challenges in terms of supply and scalability. Grid-connected microgrids can supply power stably and are being built, so they can be used as virtual ESS to provide flexibility to the power system. This study proposes an approach to determine the optimal Power Conversion System (PCS) and battery capacity for a Virtual Energy Storage System(VEES) based on a grid-connected microgrid incorporating Photovoltaic (PV) and ESS. In this paper, it is assumed that microgrids can provide flexibility to the grid by participating in the energy trading market, there are corresponding profits and penalties for order. Numerical examples are performed to demonstrate the effectiveness of the proposed method.