Shifting from an individual vision to a community vision, also in the field of buildings, is a great challenge of our times. Notably, the deployment of energy district/community concepts is crucial to enable the energy transition with a view to sustainable urban growth. In this regard, the optimal combination of building design/retrofit, renewables, and energy storage systems, is challenging and crucial to achieve the net-zero energy district (n-ZED) and ZED targets. The latter is more stringent because it means an energy-independent district, without the need of energy from the grid. To understand how to achieve such ambitious targets, this paper addresses a real case study, i.e., a small building stock in Monterusciello (suburb of Naples, coastline, Southern Italy), composed of 29 residential buildings with poor energy performance as concerns both envelopes and systems. A comprehensive optimization approach is implemented to drive the energy transition of the stock to a community to minimize energy consumption and related environmental footprint. Accordingly, sundry scenarios are investigated to provide guidelines about different strategies to reach the n-ZED and ZED targets, including full-roof photovoltaic systems, efficient reversible heat pumps, refurbishment of building envelopes, and energy storage systems, i.e., batteries and compressed air energy storage, considering different size. Energy is shared by the buildings creating a community. The energy retrofit of the district is investigated in order to find different solutions to achieve n-ZED and ZED performance, using EnergyPlus as simulation tool and MATLAB®? as optimization engine. The optimal solutions are compared to a traditional individual vision addressing the retrofit of each single building without shared energy and plants. Results show that sharing energy can be a powerful tool – if combined with optimization – enabling a more significant reduction of building environmental footprint compared to standard retrofit approaches.