Energy and momentum as partial derivatives of on-shell action in field theory According to L&L, if we fix the initial position of a particle at a given time and consider the on-shell action as a function of the final coordinates and time, $S(q_1, \ldots, q_n, t)$, then...
$$E = -\frac{\partial S}{\partial t}$$
$$p_i = \frac{\partial S}{\partial q_i}$$
Is there a straightforward generalization of this to field theory? Something that would give the energy and momentum densities by differentiating the on-shell action (with respect to... something)?
 A: Yes indeed there is!
Firstly, the normal Hamilton-Jacobi equation goes through, so still the energy is given by the time derivative of the on-shell action.
But the relevant local object that is most natural in field theory is the stress-energy-momentum tensor, which contains densities and fluxes of energy and momentum. The question of what to vary to get this is perhaps unclear at first: the answer is to vary the background geometry on which the theory is defined.
More specifically, one varies the metric, which defines the local notions of distances and angles. In fact, in the end this turns out to be the best way to define the stress-energy tensor: it's (up to constants) the derivative of the action with respect to the background metric.
Incidentally, in gravitational theories such as GR the metric itself is a dynamical field, so this on-shell variation of the action with respect to the metric is by definition zero: one may define a "matter" stress-energy by just including part of the action, but there is no good local definition of total energy density and related things in such theories.
A: Yes, this is e.g considered in Ref. 1. In field theory, the starting point is the off-shell action$^1$
$$\tag{1}  I[\phi; t_f,t_i]
~:=~\int_{t_i}^{t_f} \! dt~\int_{\Sigma} d^3x~
 {\cal L}(\phi(x,t),\dot{\phi}(x,t), \partial_x \phi(x,t);x,t) ,  $$ 
where $t_i$ and $t_f$ denote initial and final times, respectively.
We now impose appropriate boundary conditions (B.C.), e.g. Dirichlet B.C.
$$\tag{2} \phi^{\alpha}(x,t_i)~=~\phi^{\alpha}_i(x) 
\qquad \text{and}\qquad   \phi^{\alpha}(x,t_f)~=~\phi^{\alpha}_f(x) . $$ 
We assume that for given B.C. (2) there exists a unique solution $\phi_{\rm cl}$ to the Euler-Lagrange equations. OP is interested in the (Dirichlet) on-shell action defined as 
$$\tag{3} S[\phi_f,t_f; \phi_i,t_i] ~:=~ I[\phi_{\rm cl}; t_f,t_i].$$
Next define (Lagrangian) momentum field
$$\tag{4} \pi_{\alpha}(x,t)
~:=~\frac{\partial {\cal L}(\phi(x,t),\dot{\phi}(x,t), \partial_x \phi(x,t);x,t)}{\partial \dot{\phi}^{\alpha}(x,t)}, $$
and energy 
$$\tag{5}  h(t)~:=~\int_{\Sigma} d^3x~\left(\sum_{\alpha}\pi_{\alpha}(x,t)\dot{\phi}^{\alpha}(x,t)
-{\cal L}(\phi(x,t),\dot{\phi}(x,t), \partial_x \phi(x,t);x,t)\right).$$
Then one may show field-theoretically$^{2}$ that

$$\tag{6}  \frac{\delta S}{\delta \phi^{\alpha}_f(x)}~=~ \pi_{\alpha}(x,t_f), \qquad \frac{\delta S}{\delta \phi^{\alpha}_i(x)}~=~ -\pi_{\alpha}(x,t_i)  ,$$

and

$$\tag{7}  \frac{\partial S}{\partial t_f}~=~-h(t_f), \qquad    \frac{\partial S}{\partial t_i}~=~h(t_i). $$

Example: A free field Lagrangian density ${\cal L} = \frac{1}{2}\phi^2$ leads to
$$ \tag{8}  S(\phi_f,t_f; \phi_i,t_i) ~=~ \frac{1}{2(t_f-t_i)} \int_{\Sigma} d^3x~(\phi_f(x)-\phi_i(x))^2 .$$
References:


*

*MTW; Section 21.1 and Section 21.2.

*L.D. Landau & E.M. Lifshitz, Mechanics, vol. 1, 1976; $\S$ 43.
--
$^1$ For actions in point mechanics, see e.g. this Phys.SE post.
$^2$ For a proof in point mechanics, see e.g. Ref. 2 and my Phys.SE answer here.
