In this paper, we address the optimal operation of energy communities, under energy production and consumption uncertainties. In the nominal case, the operational problem is formulated as the maximization of the profit of the community over a given time horizon. Inspired by the regulation adopted in Italy since 2020, the profit includes an incentive for the self-consumption realized at the community level in each time period. In the presence of uncertainties, we use a robust formulation aiming at maximizing the worst profit achievable when energy production and consumption deviate from their nominal values. The model results in a robust scheduling policy of battery charging/discharging, guaranteeing feasible operation of the community in all scenarios of the uncertainty set. On the other hand, numerical results show that the nominal scheduling policy may suffer from a high constraint violation probability.