In this paper, a sizing method is proposed for photovoltaic (PV) and battery energy storage systems (BESSs) for buildings with demand side management capability. Three objective functions (OF) are defined, describing the self-sufficiency of the building, the net-present value of the investment in PV and BESS, and their combination in a joint expression, respectively. The latter OF provides cost-effective solutions that are potentially more profitable in case of future high increase of the electricity cost. Two analysis methods are developed to find the optimal solution under a predefined load shifting strategy. The first one applies an exhaustive search by examining all possible combinations of PV and BESS capacity. The drawback of this method is the high computational burden due to unnecessary access to the solution space. The second method is implemented with a particle swarm optimization (PSO) variant, namely the unified-PSO. Under this approach, the analysis algorithm is guided in the solution space toward efficient solutions under lower computational time. The comparative assessment of the two methods in both residential and industrial sites verifies that via the PSO algorithm the optimal solutions are found under lower execution time.