In Europe, 70% of citizens live in urban areas and consume around 75% of the primary energy supply. In order to reduce the impact of energy consumption and improve the competitiveness of local energy systems, Energy Communities may help to address the challenges of urban sustainability and energy security through local energy production and self-consumption. Solar, biomass and wind are the main sources of renewable energy that are generally used in cities. However, not all the sources available in urban environment are usable, due to the limited availability, or other technical or non-technical limits and constraints. In order to promote renewable energy technologies in buildings it is necessary to consider architectural, cultural, energy, technical and economic feasibility. This work defines a methodology for the optimal design of grid connected PV-battery systems in urban environments. The model was applied to two districts located in the city of Turin with the aim of evaluating the technical feasibility of combining multiple residential users at city level. The purpose of this work is to promote self-consumption and self-sufficiency from the network, using the integration of solar energy with PV-battery systems, and to reduce electrical losses in favor of both the single user and the distribution system. Results show that different values of self-sufficiency and self-consumption can be reached depending on the shape and dimension of each building. It was shown that it is possible to satisfy the current requirements to become an Energy Community in an urban environment with good levels of self-sufficiency.