Recent developments have increased the availability and prevalence of renewable energy sources (RESs) in grid-connected microgrids (MGs). As a result, the operation of an MG with numerous RESs has received considerable attention during the past few years. However, the variability and unpredictability of RESs have a substantial adverse effect on the accuracy of MG energy management. In order to obtain accurate outcomes, the analysis of the MG operation must consider the uncertainty parameters of RESs, market pricing, and electrical loads. As a result, our study has focused on load demand variations, intermittent RESs, and market price volatility. In this regard, energy storage is the most crucial facility to strengthen the MG’s reliability, especially in light of the rising generation of RESs. This work provides a two-stage optimization method for creating grid-connected MG operations. The optimal size and location of the energy storage are first provided to support the hosting capacity (HC) and the self-consumption rate (SCR) of the RESs. Second, an optimal constrained operating strategy for the grid-connected MG is proposed to minimize the MG operating cost while taking into account the optimal size and location of the energy storage that was formerly determined. The charge–discharge balance is the primary criterion in determining the most effective operating plan, which also considers the RES and MG limitations on operation. The well-known Harris hawks optimizer (HHO) is used to solve the optimization problem. The results showed that the proper positioning of the battery energy storage enhances the MG’s performance, supports the RESs’ SCR (reached 100% throughout the day), and increases the HC of RESs (rising from 8.863 MW to 10.213 MW). Additionally, when a battery energy storage system is connected to the MG, the operating costs are significantly reduced, with a savings percentage rate of 23.8%.