Infections disturb metabolic homeostasis in many contexts, but the underlying connections are not completely understood. To address this, we use paired genetic and computational screens in Drosophila to identify transcriptional regulators of immunity and pathology and their associated target genes and physiologies. We show that Mef2 is required in the fat body for anabolic function and the immune response. Using genetic and biochemical approaches, we find that MEF2 is phosphorylated at a conserved site in healthy flies and promotes expression of lipogenic and glycogenic enzymes. Upon infection, this phosphorylation is lost, and the activity of MEF2 changes--MEF2 now associates with the TATA binding protein to bind a distinct TATA box sequence and promote antimicrobial peptide expression. The loss of phosphorylated MEF2 contributes to loss of anabolic enzyme expression in Gram-negative bacterial infection. MEF2 is thus a critical transcriptional switch in the adult fat body between metabolism and immunity.