Energy Management System For Smart Buildings And Microgrids Using Sampling-Based Model Predictive Control (Sbmpc) And Machine Learning