A function $f: M\rightarrow N$ is defined to be continuous iff $\forall$ open set $U\subseteq N$, the preimage of $U$ is also open.
I was trying to prove that such a definition would be equivalent to the $\epsilon -\delta$ definition in a metric space, and I could only do so if I assume $f$ is surjective, or otherwise a counterexample would be $g: \mathbb{R}\rightarrow\mathbb{R}$ where $g(x)=x^2$. As if I take $U=(-1,1)$, then its preimage is $[0,1)$, which is neither open or closed. In fact, any $U$ containing elements that cannot be achieved by $g$ would face the same problem.
So I was wondering that have I remembered the definition of preimage wrong, or do I need to make sure that $U$ must be chosen from the image set of $f$?
You're probably confusing the mapping $x\mapsto x^2$ with $x\mapsto\sqrt{x}$, which is defined on $\mathbb{R}_{\ge0}$ (the set of non negative real numbers), with values in $\mathbb{R}$.
In this case it's indeed true that the inverse image of $(-1,1)$ is $[0,1)$, but this set is open in $\mathbb{R}_{\ge0}$, because, for instance, $$ [0,1)=(-1,1)\cap\mathbb{R}_{\ge0} $$ and so $[0,1)$ is an open set in the relative topology on $\mathbb{R}_{\ge0}$.
The inverse image of $(-1,1)$ with respect to the mapping $x\mapsto x^2$ is $$ \{x\in\mathbb{R}:x^2\in(-1,1)\} $$ and this is again $(-1,1)$. The fact that the function maps $(-1,1)$ onto $[0,1)$ is of no concern, because we're interested in inverse images, not in direct images and a continuous function can map open sets onto non open ones.
Elements in the codomain that are not in the image of the function make no problem.