Suppose $f(x)$ defined in $\mathbb{R}$, then $f$ is continuous in $\mathbb{R}$ if and only if for every open set $G$, the set $f^{-1}(G)=\{x:f(x)\in G\} $ is open.
I have done necessity.
If $f$ is continuous and G is open. Then for $x_0\in f^{-1}(G)$,$f(x_0)\in G$,and $f$ is continuous hence $\exists U(x_0,\delta)$,such that for $x\in U(x_0,\delta)$,$f(x)\in G$. Thus $ U(x_0,\delta)\subset f^{-1}(G)$ which makes $f^{-1}(G)$ is an open set.
And now I have no ideal of the sufficiency.
Hint: Fix $x \in \mathbb R$. We'll show that $f$ is continuous at $x$. So, fix your favorite $\epsilon > 0$ and consider the open set $(f(x) - \epsilon, f(x) + \epsilon)$. Its preimage under $f$ is open and has the elements $x$. Hence it contains an open interval around $x$. But now the (pointwise) image of that open interval...