so you've established more or less that we need to look at idempotents in the rings $\Bbb Z/N\Bbb Z$. You can decompose $\Bbb Z/N \Bbb Z$ by the chinese remainder theorem. If $N$ is a prime power, you have a local ring, which implies the only idempotents are $0$ and $1$. If you have a product $R \times S$, idempotents are of the form $(e,f)$ where $e \in R, f \in S$ are idempotent.
In particular, you get that the number of non-unital homomorphisms $\Bbb Z \to \Bbb Z/N\Bbb Z$ is $2^{\omega(N)}$, where $\omega$ denotes the number of distinct prime factors of $N$