Initially in the fasting state the body will preferentially utilize stored muscle and liver glycogen to generate energy. Once those are depleted, the liver (mainly) will conduct gluconeogenesis using products from the beta oxidation of fatty acids liberated from adipose tissue. Beta oxidation itself produces electrons (NADH and FADH2) for the ETC as well as acetyl CoA which can be used to make ketone bodies or do gluconeogenesis. The body will prioritize the supply of energy to the brain where the generated ketone bodies will go.
All of this is regulated by the balance of hormones like insulin (high the fed state, promotes adipogenesis and glycogen storage, inhibits fatty acid oxidation and hence inhibits ketogenesis and gluconeogenesis) and glucagon (high in the fasting state, essentially does the opposite of insulin).