This paper presents a two-level control scheme for the energy management of an electricity prosumer node equipped with controllable loads, local generation, and storage devices. The main control objective is to optimize the prosumer's energy bill by means of intelligent load shifting and storage control. A generalized tariff model including both volumetric and capacity components is considered, and user preferences as well as all technical constraints are respected. Simulations based on real household consumption data acquired with a sampling period of 1 s are discussed. The proposed control scheme bestows the prosumer node with the flexibility needed to support smart grid use cases such as bill optimization (i.e., local energy trading), control of the profile at the point of connection with the grid, demand response, and reaction to main supply faults (e.g., islanding operation), etc.