Exploiting Building Demand Flexibility Through Machine Learning for Building-to-grid Integration