Proof (preimage of open or closed set under continuous function is open or closed)

Preimage preserves openness $\implies$ continuity

Suppose for all open set $V$ in $Y$, $f\inv(V)$ is open in $X$.

Then for all point $x_0\in X$ and neighbourhood $U$ of $f(x_0)$, there exists an open set $V\subseteq U$ where $f(x_0) \in V$. Then by hypothesis, $f\inv(V)$ is open. Since $x_0 \in f\inv(V) \subseteq f\inv(U)$, $f\inv(U)$ is a neighbourhood of $x_0$.

Therefore $f$ is continuous.

Continuity $\implies$ preimage preserves openness

Suppose $f$ is continuous and $V$ is an open set in $Y$.

For each $x\in f\inv(V)$, we have $f(x)\in V$ and so $f(x)$ has an open neighbourhood $V$. By continuity, $f\inv(V)$ is a neighbourhood of $x$, so there exists an open set $U$ such that $x\in U\subseteq V$ (or in a metric space, $r>0$ such that $B_r(x) \subseteq f\inv(V)$).

Hence $f\inv(V)$ is open.

Preimage preserves openness $\implies$ preimage preserves closedness

Suppose for all open set $V$ in $Y$, $f\inv(V)$ is open in $X$.

Let $U$ be an closed set in $Y$. Then $Y\setminus U$ is open. Therefore $f\inv(Y\setminus U)$ is open in $X$. Note that $$ \begin{align*} f\inv(Y\setminus U) = f\inv(Y) \setminus f\inv(U) = X \setminus f\inv(U). \end{align*} $$ So $f\inv(U) = X\setminus (X\setminus f\inv(U))$ is closed.

Preimage preserves closedness $\implies$ preimage preserves openness

Replace the words "open" with "closed" and vice versa in the last section.