Using a calculus of variations approach, we determine the shape of a typical plane partition in a large box (i.e., a plane partition chosen at random according to the uniform distribution on all plane partitions whose solid Young diagrams fit inside the box). Equivalently, we describe the distribution of the three different orientations of lozenges in a random lozenge tiling of a large hexagon. We prove a generalization of the classical formula of MacMahon for the number of plane partitions in a box; for each of the possible ways in which the tilings of a region can behave when restricted to certain lines, our formula tells the number of tilings that behave in that way. When we take a suitable limit, this formula gives us a functional which we must maximize to determine the asymptotic behavior of a plane partition in a box. Once the variational problem has been set up, we analyze it using a modification of the methods employed by Logan and Shepp and by Vershik and Kerov in their studies of random Young tableaux.