Residential buildings are currently equipped with energy production facilities, e.g., solar rooftops and batteries, which in conjunction with smart meters, can function as smart energy hubs coordinating the loads and the resources in an optimal manner. This paper presents a mathematical model for the optimal energy management of a residential building and proposes a centralized energy management system (CEMS) framework for off-grid operation. The model of each component of the hub is integrated within the CEMS. The optimal decisions are determined in real-time by considering these models with realistic parameter settings and customer preferences. Model predictive control (MPC) is used to adapt the optimal decisions on a receding horizon to account for the deviations in the system inputs. Simulation results are presented to demonstrate the feasibility and effectiveness of the proposed CEMS framework. Results show that the proposed CEMS can reduce the energy cost and energy consumption of the customers by approximately 17% and 8%, respectively, over a day. Using the proposed CEMS, the total charging cycles of the ESS were reduced by more than 50% in a day.