The maximal infinite cyclic subgroups are of the form you mentioned (to get all infinite cyclic subgroups you also need to include their finite index subgroups). This follows from Theorem 1.4 in Sarnak, Peter, Class numbers of indefinite binary quadratic forms. J. Number Theory 15 (1982), no. 2, 229--247 since the generator of such a subgroup must be a primitive hyperbolic element.
Edited: Oops, I missed that $\mathrm{SL}_2(\mathbb{Z})$ also has infinite cyclic subgroups generated by parabolic elements, but those are also stabilizers of quadratic forms of discriminant $0$ (that is, that are squares)).