The flatband voltage is obtained when the applied gate voltage equals the workfunction difference between the gate metal and the semiconductor (VFB = Fm - Fsc).
The flatband voltage of real MOS structures is further affected by the presence of charge in the oxide or at the oxide-semiconductor interface. In this case, the flatband voltage still corresponds to the voltage, which, when applied to the gate electrode, yields a flat energy band in the semiconductor: Refere to Chapter 6 in my Book (Electronic Devices and Circuits From A to Z), which is available HERE in ResearchGate.