In this paper, the size of the battery bank of a grid-connected PV system is optimized subjected to the objective function of minimizing the total annual operating cost, ensuring continuous power supply within the frame work of system operation constraints using Improved Harmony Search Algorithm (IHSA). The load flow is carried out with peak load shaving where the state of charge (SOC) of the batteries is not allowed to lower beyond a certain value during sunshine hour. The feed-in-tariff plan is adopted, where power can be bought from the grid as well as can be sold back to the grid in case of surplus power. So a net metering system at consumer end calculates the net electricity cost. Depending upon the peak/off-peak hours and availability of sunshine, the system charges or discharges the storage to supply the demand. The outcomes verify that the IHSA is an efficient, robust and fast optimization technique.