In response to the COVID-19 pandemic, there has been a notable shift in literature towards enhancing indoor air quality and public health via Heating, Ventilation, and Air Conditioning (HVAC) control. However, many of these studies simplify indoor dynamics using ordinary differential equations (ODEs), neglecting the complex airflow dynamics and the resulted spatial-temporal distribution of aerosol particles, gas constituents and viral pathogen, which is crucial for effective ventilation control design. We present an innovative partial differential equation (PDE)-based learning and control framework for building HVAC control. The goal is to determine the optimal airflow supply rate and supply air temperature to minimize the energy consumption while maintaining a comfortable and healthy indoor environment. In the proposed framework, the dynamics of airflow, thermal dynamics, and air quality (measured by CO 2 concentration) are modeled using PDEs. We formulate both the system learning and optimal HVAC control as PDE-constrained optimization, and we propose a gradient descent approach based on the adjoint method to effectively learn the unknown PDE model parameters and optimize the building control actions. We demonstrate that the proposed approach can accurately learn the building model on both synthetic and real-world datasets. Furthermore, the proposed approach can significantly reduce energy consumption while ensuring occupants' comfort and safety constraints compared to existing control methods such as maximum airflow policy, model predictive control (MPC) with ODE models, and reinforcement learning.