Handling of varying energy sources and flexible connection to smart grids is a current challenge. Minimizing the overall monetary cost and maximizing the use of renewable energy sources are not the exclusive optimization goals, but also guaranteeing the thermal comfort is an important goal. This paper deals with a comprehensive approach of a mixed-integer quadratic-programming model predictive control scheme based on the thermal building model and the building energy management system. Calculating the global optima while handling continuous and binary constraints as well as variables and considering both the thermal and electrical part of a smart home are the key aspect of the proposed model predictive controller. By inclusion of disturbance forecasts, occupancy prediction, and individual user weights the control scheme is optimally suited for implementation in real buildings. Furthermore, the occupancy prediction in this research is based on an unsupervised method, which is useful for an effective implementation. This work demonstrates the optimal management of appliances such as heating, a battery storage, a freezer, a dishwasher, a photo-voltaic system, and the opportunities to buy from and sell to the smart grid. Optimal utilization of the building’s thermal storage capacity helps to minimize necessary battery capacity. Simulation results underline the efficient global optimization while demonstrating all proposed features of the complex control scheme.