Ignore the points $A,B,C,D$ in the following sketch.

The translation corresponds to the change of variables
$$x=\overline{x}+X,\qquad y=\overline{y}+Y,\tag{1}$$
and the rotation corresponds to
$$X=x^{\prime }\cos \theta -y^{\prime }\sin \theta,\qquad Y=x^{\prime }\sin \theta +y^{\prime }\cos \theta .\tag{2}$$
If you combine $(1)$ and $(2)$, you get
$$x=\overline{x}+x^{\prime }\cos \theta -y^{\prime }\sin \theta,\qquad y=\overline{y}+x^{\prime }\sin \theta +y^{\prime }\cos \theta .\tag{3}$$
You can invert this system of equations to get $x',y'$ in terms of $x,y$
and $\overline{x},\overline{y}$:
$$x^{\prime }=x\cos \theta +y\sin \theta -\overline{x}\cos \theta -\overline{y}\sin \theta \tag{4a}$$
$$y^{\prime }=-x\sin \theta +y\cos \theta +\overline{x}\sin \theta -\overline{y}\cos
\theta .\tag{4b}$$
The rotation and the translation transformation can be expressed by matrices. The rotation transformation in two dimensions is described in this Wikipedia section.