To enable the efficient utilization of energy carriers and the successful integration of renewable energies into energy systems, building energy management systems (BEMS) are inevitable. In this article, we present a modular BEMS and its customizable architecture that enable a flexible approach towards the optimization of building operation. The system is capable of handling the energy flows in the building and across all energy carriers as well as the interdependencies between devices, while keeping a unitized approach towards devices and the optimization of their operation. Evaluations in realistic scenarios show the ability of the BEMS to increase energy efficiency, self-consumption, and self-sufficiency as well as to reduce energy consumption and costs by an improved scheduling of the devices that considers all energy carriers in buildings as well as their interdependencies.