Transmission system operators impose several grid-code constraints on large-scale wind farms to ensure power system stability. These constraints may reduce the net profit of the wind farm operators due to their inability to sell all the power. The violation of these constraints also results in an imposition of penalties on the wind farm operators. Therefore, an operation strategy is developed in this study for optimizing the operation of wind farms using an energy storage system. This facilitates wind farms in fulfilling all the grid-code constraints imposed by the transmission system operators. Specifically, the limited power constraint and the reserve power constraint are considered in this study. In addition, an optimization algorithm is developed for optimal sizing of the energy storage system, which reduces the total operation and investment costs of wind farms. All parameters affecting the size of the energy storage systems are also analyzed in detail. This analysis allows the wind farm operators to find out the optimal size of the energy storage systems considering grid-code constraints and the local information of wind farms.