If you take the gradient of $f$ you have
$$
\nabla f = ( y - 2, x)' = (0,0)',
$$
i.e., the critical point is $(0,2)$ which lies outside of your domain. As such, you'll get the global maximum and minimum in $D$ on $\partial D$. Namely, check for $-1 \le x \le 1$ and $y=0$, and you'll get
$$
g(x)= -2x,
$$
that is monotone decreasing function, i.e., $(-1, 0)$ is a candidate point. For $y=1$ you have
$$
g(x) = x - 2x,
$$
hence $(-1, 1)$ is a candidate point.
Then, check $x=1$ and $0 \le y \le 1$, thus
$$
g(y)= y - 2,
$$
i.e., $(1,1)$i is another candidate. For $x=-1$ you'll get
$$
g(y)=-y+2,
$$
so $(-1,0)$ is another point. Finally, check the connection points of the $4$ parts of $\partial D$, i.e., $(-1, 0)$, $(-1,1)$, $(1, 0)$ and $(1,1)$ that are mostly the same candidates as in the aforementioned analysis. Finally, just compare $f$ in all of these points.