Efficient operation is essential in order to tackle the increasing energy needs of residential and commercial buildings. In this context, building automation systems (BASs) provide a basis for advanced control of devices and appliances in building energy management systems (BEMSs) with respect to comfort compliance as well as energy consumption. Furthermore, proceeding smart grid integration of buildings benefits comprehensive energy management. Nevertheless, the heterogeneity in smart grid communication and building automation (BA), the lack of machine-readable semantics, and the tailoring of BEMSs to specific building types or comfort domains limit the development of flexible and reusable energy management solutions for cost-efficient and large-scale deployment. This thesis presents the design of a BEMS based on a semantic abstraction layer that separates the generic optimization from the building environment. First, Web services are used for interoperable integration of BASs while an IP-centric protocol stack is defined for homogeneous smart grid communication. Second, BEMS-related information is abstracted and merged in an ontology as part of the semantic abstraction layer. In addition, a service-oriented interface is elaborated for semantic machine-to-machine communication based on this ontology. Third, the machine-readable information modeled in the ontology is exploited to support automated configuration and operation of optimization in BEMSs. A workflow for the extraction of optimization problems is defined in order to determine constraints, variables, and constants of an objective function. Data-driven models for time series prediction are generated in order to support the optimization. Based on this, universally applicable optimization strategies enable the identification of energy-efficient schedules for BASs. Proof-of-concept implementations and prototypes are realized for the evaluation of the individual contributions. Feasibility analysis and case studies are used to demonstrate the applicability and functionality as well as to discuss the benefits and open issues of the approach. Overall, this work contributes to interoperable integration of smart grid communication and BA combined with abstract semantic modeling of BEMS-related context information in order to uncouple optimization from building and technology specifics. The automated and generic design process enables the reusable application for energy management optimization in smart buildings.