Which differential equations allow for a variational formulation? Many ODE's and PDE's arising in nature have a variational formulation. An example of what I mean is the following. Classical motions are solutions $q(t)$ to Lagrange's equation
$$
\frac{d}{dt}\frac{\partial L(q,\dot q)}{\partial\dot q}=\frac{\partial L(q,\dot q)}{\partial q},
$$
and these are critical points of the functional
$$
I(q)=\int L(q,\dot q)dt.
$$
Of course one needs to be precise with what considers a solution to both equations. This amounts to specifying regularity and a domain of the functional. This example is an ODE, but many PDE examples are possible as well (for example electromagnetism, or more exotic physical theories). Once one knows a variational description of the problem, many more methods are available to solve the problem. 
Now I do not expect that any PDE or ODE can be viewed (even formally) as a critical point of a suitable action functional. This is because this whole set up reminds me of De Rham cohomology: "which one-forms (the differential equations) are exact (that is, the $d$ of a functional)?". The last sentence is not correct, but the analogy maybe is? Anyway, my question is:

Are there any criteria to determine if a given differential equation admits a variational formulation?

 A: I remember idly wondering about this once and found that Anderson's work on the variational bicomplex satisfied my idle curiosity.
A: Others give useful references that discuss what is known about the answer, but no statement of the answer itself. The relevant algebraic setting is the variational bicomplex, which is discussed in the works of Anderson and others. In this setting, there are two differentials, the horizontal differential $d_H$ (representing derivatives with respect to independent variables like $t$) and the vertical differential $d_V$ (representing variational derivatives with respect to dependent variables like $q(t)$). Each of these differentials is "de Rham-like" and they anticommute with each other, which explains the cohomological flavor of the answer. A rough statement of the answer is as follows.
A Lagrangian $L$ density gives rise to a set of Euler-Lagrange equations $E_i=0$ as follows:
$$ d_V L = E_i ~ d_V q^i - d_H\theta , $$
that is, the vertical 1-form $E_i ~ d_V q^i$ is vertically exact (up to a horizontally exact term $d_H \theta$). So, it is necessary for $E_i=0$ to be the Euler-Lagrange system of some Lagrangian that $E_i ~ d_V q^i$ is closed up to a horizontally exact term, namely
$$ d_V(E_i~d_V q^i) = d_H \theta' (= -d_H d_V \theta) . $$
In fact, the same condition is also sufficient, up to obstructions related to the global topology of the manifold where the dependent variables $q$ take their values. This condition was formulated already classically by Helmholtz.
However, the above statement is restrictive in that it answers the question only when $E_i=0$ is already in Euler-Lagrange form. However, there are many transformations that one can apply to the system $E_i=0$ that gives an equivalent system $F_a=0$. Given only the system $F_a=0$, is it still possible to decide whether it is equivalent to some system $E_i=0$ in Euler-Lagrange form? This is the hard inverse problem (aka the multiplier problem). The only general result that I'm aware of in that direction is this.

If there exists a form $\omega$ of vertical degree 2 and horizontal degree $n-1$, where $n$ is the number of independent variables, such that it is both horizontally and vertically closed modulo the equations $F_a=0$ (namely $d_V \omega = A^a F_a$ and $d_H \omega = B^a F_a$), then there exists (again, up to global topological obstructions) a Lagrangian density $L$ whose Euler-Lagrange equations $E_i=0$ are equivalent to a subsystem of $F_a=0$.

To my knowledge, the above observation first appeared in Henneaux (AnnPhys, 1982) for ODEs and in Bridges, Hydon & Lawson (MathProcCPS, 2010) for PDEs. The calculation demonstrating this observation is given in a bit more detail on this nLab page. (Edit: At risk of shameless self-promotion, I'll also note that I collected these observations in a self-contained paper (arXiv; JMP, 2013).)
It reduces the solution of the hard inverse problem to classifying all such forms $\omega$ (corresponding to the so-called characteristic cohomology of the variational bicomplex restricted to $F_a=0$ in the corresponding degree) and checking that there exists a candidate that gives rise to a Lagrangian density whose Euler-Lagrange system $E_i=0$ is equivalent to the full system $F_a=0$. The calculation of the corresponding characteristic cohomology of the system $F_a=0$ is still non-trivial, but there exist ways of attacking it, which include Vinogradov's $\mathcal{C}$-spectral sequence mentioned in other responses.
A: Well this is a classical problem known as "The inverse problem in the calculus of variations". There is a huge amount of references on the problem you can google at.  The problem as if the system $y_i''=F(x,y_j,y_j')$, $i=1,2,..,n$ can be identified with extremals of the equation $\int \phi(x,y_j,y_j') \rightarrow min$ amounts to solving the system of pdes for the partial derivatives of $\phi$, say $\phi_{ij}$. Davis [1928] restated the problem as that of finding an integrating factor $P_{ij}$ such that the system $P_{ij}(F_j-y_j'') = E(\phi)$,where $E$ denotes the Euler-Lagrange operato. There appears some condition on self-adjointness The case $n=2 $ was solved by the first Field medalist Jesee Douglas (1941). He used Riquier-Janet theory. For $n>2$ it remain possible except for cumbersome cases. Spencer and Quillen introduced the Spence cohomology to give suficient conditions for the overdetermined system to become integrable. Some references:
1) The inverse problem on the calculus of variations\ldots W. Sarlet, G. thompson, G.E.  Prince. TAMS 354, Num.7, 2897-2919, 2002.
2) Overdetermined systems of linear PDEs. D.C. Spencer., 1969 (sorry Idon't have the complete reference at hand).
3)J. Douglas. Solution to the inverse problem of the calculus of variations. TAMS 50 (1941), 71-128.
Professor Peter Olver (University of Minnesota) is probably one of the major authorities on the topic.
A: There is a huge  amount of literature on this problem. I include some works that seem "classic" and that I've consulted at some point:
Tulczyjew:
Link
http://www.numdam.org/numdam-bin/fitem?id=BSMF_1977__105__419_0
Takens:
Link
And the work of Anderson on the variational bicomplex (I think this complex was introduced by I.M. Gelfand circa 1970).
There is also quite a bit of good work by Vinogradov and his school (the C-spectral sequence). All this is mostly applications of homological algebra to the theory of PDE's.
