If you don't mind working with complex numbers (although $x$ and $y$ are both complex anyway), you can use the fact that
$$ 2\cos \theta = e^{i\theta} + e^{-i\theta} $$
and conclude that $x = e^{iA}$, $y = e^{iB}$. Then
$$ 2\cos(A-B) = e^{i(A-B)} + e^{-i(A-B)} = \frac{x}{y} + \frac{y}{x} $$
Technically, there are 4 multiple possibilities depending on how you pick the sign
$$ x = e^{\pm iA}, \ y = e^{\pm iB} $$
An alternate result would be if $x =e^{iA}$, $y = e^{-iB}$. Then
$$ 2\cos(A-B) = xy + \frac{1}{xy} $$
Another approach without using Euler's identity is to find
$$ 4\sin^2 A = 4 - \cos^2 A = 4 - \left(x + \frac{1}{x}\right)^2 = 2 - x^2 - \frac{1}{x^2} = -\left(x - \frac{1}{x}\right)^2 $$
Therefore
$$ 2\sin A = \pm i\left(x - \frac{1}{x}\right), \ 2\sin B = \pm i\left(y - \frac{1}{y}\right) $$
Then apply the difference of angles formula
$$ \begin{align}
4\cos(A-B) &= 4\cos A\cos B + 4\sin A\sin B \\
&= \left(x + \frac{1}{x}\right)\left(y + \frac{1}{y}\right) \pm \left(x - \frac{1}{x}\right)\left(y - \frac{1}{y}\right)
\end{align} $$