The Hamilton-Jacobi partial differential equation (HJE) aims to find the generator g(q,P,t) of a canonical transformation such that the trajectories are described by (Q,P)=\text{const}. This means that the new Hamiltonian must obey
\partial_Q H'(Q,P,t)=\partial_P H'(Q,P,t)=0.
This means that the new Hamiltonian is a function of time only:
H'(Q,P,t)=H(q,p,t)+\partial_t g(q,P,t)=f(t).
However, without any change of generality you can add an arbitrary function of time only to g, and thus you can as well demand that
H'(Q,P,t)=H(q,p,t)+\partial_t g(q,P,t)=0.
Since now p=\partial_q g, you get
H \left (q,\partial_q g,t \right ) + \partial_t g=0.
For a system with f configuration degrees of freedom, any solution of this partial differential equation of a function of f+1 independent variables q and t must contain f+1 integration constants. One of these is trivial since it just adds a constant to H' which is irrelevant. Thus you have f integration constants that you identify with the new canonical momenta P. The trajectories of the system are then given by
Q^k=\frac{\partial g}{\partial P_k}=\text{const}.
If H=H(q,p), i.e., if the Hamiltonian is not explicitly time dependent, due to Noether's theorem it's constant. That means
H=E=\text{const}\; \Rightarrow\; \partial_t g=-E \; \Rightarrow \; g(t,q,P)=-E t+S(q,E,P_2,\ldots,P_f).
Here, we have chosen the energy value as one of the new canonical momenta, i.e., set P_1=E. The corresponding new configuration variable then is
Q^1=\partial_E g=-t+\partial_E S.
In a similar way you can simplify the task if one of the configuration variables is cyclical, i.e., if the Hamiltonian doesn't depend on it. Then the corresponding canonical momentum is conserved, and you can keep it as one of the new momenta.
Note that, against the claim in Landau, Lifgarbages Vol. 1, in general there are not enough conservation laws to solve the HJE completely. That's the case only for integrable systems. For a more mathematical treatment of these issues see,
V. Arnold, Classical Mechanics, Springer.