Photovoltaic-battery energy systems (PV-BESs) have recently emerged as a promising alternative energy solution for electricity consumers. Due to the high level of unpredictability and intermittency associated with solar energy, the optimal sizing and intermittency mitigation of PV-BESs is necessary while integrating them into the grid. This paper presents a technical and economical model for the optimal sizing of a grid-connected PV-BES system for different battery technologies. An iterative analytical approach is utilized to determine the battery capacity, generate multiple combinations of PV-BES over a defined range of PV rated power, and apply a proper energy management strategy to control the energy flow through the system. This is followed by an economic model to calculate the system levelized cost of energy (LCOE) for all possible PV-BES sizes. The optimal PV size and best BES coupled with the PV system is chosen depending on the minimum LCOE. In this context, an improved formula of LCOE is proposed which includes new parameters reflecting the impact of surplus PV output and the energy purchased from the grid. Additionally, the proposed model uses the levelized cost of delivery (LCOD) for BES and compares it with system LCOE. Data over one year of hourly solar irradiation, temperature and load demand are used for system sizing. The results show that the minimum system LCOE is observed when the PV rated power is 710 KW, and the most suitable BES in conjunction with the PV system is redox flow battery with 1 MWh capacity. A cost reduction of 18% obtained compared to the grid electricity price. Moreover, the proposed model allows 75% of self-consumed energy by the PV-BES compared to 48% when using the PV system alone.