The optimization of the energy system serving users’ aggregations at urban level, such as Energy Communities, is commonly addressed by optimizing separately the set of energy conversion and storage systems from the scheduling of energy demand. Conversely, this paper proposes an integrated approach to include the demand side in the design and operation optimization of the energy system of an Energy Community. The goal is to evaluate the economic, energetic, and environmental benefits when users with different demands are aggregated, and different degrees of flexibility of their electricity demand are considered. The optimization is based on a Mixed-Integer Linear Programming approach and is solved multiple times by varying (i) the share of each type of user (residential, commercial, and office), (ii) the allowed variation of the hourly electricity demand, and (iii) the maximum permitted CO2 emissions. Results show that an hourly flexibility of up to 50% in electricity demand reduces the overall system cost and the amount of energy withdrawn from the grid by up to 25% and 31%, respectively, compared to a non-flexible system. Moreover, the aggregation of users whose demands match well with electricity generation from renewable sources can reduce CO2 emissions by up to 30%.