The determination of band alignments and defect levels is demonstrated for the technologically relevant Si-SiO2-HfO2 gate stack. The proposed scheme, which combines first-principles molecular dynamics for model generation and hybrid density functionals for electronic-structure calculations, yields band offsets in close agreement with experiment. Charge transition and pinning levels associated with oxygen vacancies are aligned with respect to the silicon band edges. The vacancies are shown to preferentially reside in the amorphous transition layer, consistent with experimental observations of Fermi-level pinning.