Assuming $m > n$, there is a method for classifying such spaces using a technique from the Postnikov tower. Namely, such a space has a map $X \to K(G,n)$ inducing an isomorphism on $\pi_n$, and if we convert this into a fibration it becomes a fiber bundle with fiber $K(H,m)$.
Such bundles are classified by a "k-invariant": an element in $H^{m+1}(K(G,n) ; H)$. One direction takes such a cohomology class, represents it as a map $K(G,n) \to K(H,m+1)$, and then takes a (homotopy) pullback. To see that this is actually a bijective correspondence requires a little bit of obstruction theory (and uses critically that $n > 1$; otherwise we'd also need to classify an action of $G$ on $H$).
One should note that if you only ask that $\pi_n X$ and $\pi_m X$ are abstractly isomorphic to $G$ and $H$ rather than choosing isomorphisms, the $k$-invariant is only well-defined up to the action of the automorphism groups $Aut(G)$ and $Aut(H)$ on $H^{m+1}(K(G,n); H)$.
If $G$ and $H$ are finitely generated abelian groups and at least one of them is finite, then Serre's work using mod-$\cal C$ theory shows that this cohomology group is finite; however, in general you can certainly have infinitely many distinct isomorphism classes (e.g. there are infinitely many homotopy types with $\pi_2 = \pi_3 = \Bbb Z$, because $H^4 K(\Bbb Z,2) \cong \Bbb Z$).