This paper presents optimal sizing algorithms of grid-connected photovoltaic-battery system for residential houses. The objective is to minimize the total annual cost of electricity. The proposed methodology is based on a genetic algorithm involving a time series simulation of the entire system and is validated using data collected through one year. Genetic algorithm jointly optimises the sizes of the photovoltaic and the battery systems by adjusting the battery charge and discharge cycles according to the availability of solar resource and a time-of-use tariff structure for electricity. Houses without pre-existing solar systems are considered. The results show that jointly optimizing the sizing of battery and photovoltaic systems can significantly reduce electricity imports and the cost of electricity for the household. However, the optimal capacity of such photovoltaic battery varies strongly with the electricity consumption profile of the household, and is also affected by electricity and battery prices. Besides individual PV generation and battery storage for each house, this paper also investigates group battery optimizations for communities with different consumption levels or with different energy demand diversity to see their effects on optimal sizing and peak demands for aggregated PV-battery system.