Calculate the impedance and phase angle of a capacitor
This works for an ideal capacitor, i.e. if you can ignore ESR

Let \$I\$ = magnitude of the current through the circuit, \$U_C\$ = magnitude of the voltage across a capacitor, and \$X_C\$ = the reactance of a capacitor (all are the positive real numbers).

As the first step, you can find \$X_C\$:
$$X_C = \frac{U_C}{I}$$

Then, using the following relation for the total impedance (as a complex number)
$$Z = R - jX_C$$
where \$j\$ is the imaginary unit, you can find the phase angle for the voltage across a capacitor
$$\varphi = -\arctan\left(\frac{X_C}{R}\right)$$

As for \$I\$ and \$U_C\$, you can find these magnitudes by averaging ADC samples over whole number of periods and scaling by \$\frac{\pi}{2}\$:
$$I = \frac{\pi}{2N}\sum_{i=1}^N |I_i|$$
$$U = \frac{\pi}{2N}\sum_{i=1}^N |U_i|$$

The \$\frac{\pi}{2}\$ factor arises from the proportion between the magnitude and the average of the absolute value for a sine wave. By the way, you can just ignore this factor, since it will be cancelled out in \$X_C = \frac{U_C}{I}\$.

If you can not ignore ESR

Then you can compute the phase shift using linear algebra. For vectors \$\mathbf{v}\$ and \$\mathbf{w}\$

$$\cos(\varphi) = \frac{\mathbf{v}\cdot \mathbf{w}}{\|\mathbf{v}\|\|\mathbf{w}\|}$$

and you can treat the sampled signals as multidimentional vectors, using

$$\mathbf{v}\cdot \mathbf{w} = \sum_{i=1}^N v_i w_i$$
$$\|\mathbf{v}\| = \sqrt{\sum_{i=1}^N v_i^2}$$

(sampling over a whole number of periods)

Substitute \$v_i = U_i\$ and \$w_i = I_i\$ for the final formula

$$\varphi = \arccos\left(\frac{\mathbf{U}\cdot \mathbf{I}}{\|\mathbf{U}\|\|\mathbf{I}\|}\right)$$

where \$U_i\$ is the sampled voltage across a capacitor and \$I_i\$ is the sampled current through the circuit.

EDIT:

In MATLAB or Octave you can try the following:

&gt;&gt; t = linspace(0, 2*pi*10, 100);
&gt;&gt; x = sin(t);
&gt;&gt; y = sin(t + 0.123);
&gt;&gt; phase_shift = acos(dot(x, y)/(norm(x)*norm(y)))
phase_shift =  0.12422


There is some error (0.12422 vs 0.123) due to relatively small number of samples (100).

By the way, \$\cos(-x) = \cos(x)\$ (even function), so you can not determine the sign. This is not a problem, since for a capacitor the sign is always the same.