In recent years, combined optimisation of Photovoltaic (PV) and Battery Energy Storage Systems (BESS) has attracted remarkable attention as a solution to increase prosumers selfconsumption while also mitigating the issues of high BESS capital costs. In this context, this work proposes a two-level optimal sizing algorithm of PV-BESS systems. The upper level is based on a Genetic Algorithm (GA) devoted to the optimisation of rated PV power and BESS power and storage capacity minimising the Levelised Cost of Energy (LCOE), whereas the lower level embeds a novel rule-based energy management system, where rules are defined considering both energy and feed-in tariffs, with tariff-dependent rules being also optimised by the GA. The algorithm is eventually tested in a Spanish reality-based case study.