This paper develops a theory of optimal taxation with behavioral agents. We use a general framework that encompasses a wide range of biases such as misperceptions and internalities. We revisit the three pillars of optimal taxation: Ramsey (linear commodity taxation to raise revenues and redistribute), Pigou (linear commodity taxation to correct externalities), and Mirrlees (nonlinear income taxation). We show how the canonical optimal tax formulas are modified and lead to novel economic insights. We also show how to incorporate nudges in the optimal taxation framework, and jointly characterize optimal taxes and nudges. (JEL D62, D91, H21)