PARTIAL SOLUTION
It seems useful to organize the problem using the method of Lagrange multipliers with multiple constraints, which transforms it into a system of 30 degree-3 polynomial equations in 30 scalar unknowns, as follows.
Call the target points $\mathbf{\tilde{p_0}},...,\mathbf{\tilde{p_7}}$.
We want to find the values of the 8 cuboid vertices (24 scalar variables):
$$\begin{aligned}
\mathbf{p_0} &= (x_0,y_0,z_0)^T \\
&... \\
\mathbf{p_7} &= (x_7,y_7,z_7)^T \\
\end{aligned}$$
that minimizes the scalar function:
$$\begin{aligned}
f(\mathbf{p_0},...\mathbf{p_7}) = \sum{{\left\lVert\mathbf{p_i}-\mathbf{\tilde{p_i}}\right\rVert}^2}
\end{aligned}$$
subject to the following 6 scalar constraints (which say that the 4 vertices of each of the 6 faces of the cuboid must be coplanar):
$$\begin{aligned}
g_0(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_2}-\mathbf{p_0})\times(\mathbf{p_3}-\mathbf{p_0}))\cdot(\mathbf{p_1}-\mathbf{p_0}) = 0 \\
g_1(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_1}-\mathbf{p_0})\times(\mathbf{p_5}-\mathbf{p_0}))\cdot(\mathbf{p_4}-\mathbf{p_0}) = 0 \\
g_2(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_4}-\mathbf{p_0})\times(\mathbf{p_6}-\mathbf{p_0}))\cdot(\mathbf{p_2}-\mathbf{p_0}) = 0 \\
g_3(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_5}-\mathbf{p_7})\times(\mathbf{p_1}-\mathbf{p_7}))\cdot(\mathbf{p_3}-\mathbf{p_7}) = 0 \\
g_4(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_3}-\mathbf{p_7})\times(\mathbf{p_2}-\mathbf{p_7}))\cdot(\mathbf{p_6}-\mathbf{p_7}) = 0 \\
g_5(\mathbf{p_0},...,\mathbf{p_7}) &= ((\mathbf{p_6}-\mathbf{p_7})\times(\mathbf{p_4}-\mathbf{p_7}))\cdot(\mathbf{p_5}-\mathbf{p_7}) = 0
\end{aligned}$$
Notice that the expressions for the $g_i$'s are $3{\times}3$ determinants which are essentially tetrahedron volumes (times 6),
so each of them can be rearranged in various ways by (evenly) permuting its 4 points, when convenient.
E.g. when we want to differentiate $g_0$ with respect to $\mathbf{p_0}$, it helps to think of it as
$g_0 = ((\mathbf{p_3}-\mathbf{p_1})\times(\mathbf{p_2}-\mathbf{p_1}))\cdot(\mathbf{p_0}-\mathbf{p_1})$, whose partial derivative with respect to $\mathbf{p_0}$
can then be clearly seen to be $(\mathbf{p_3}-\mathbf{p_1})\times(\mathbf{p_2}-\mathbf{p_1})$ (a row vector).
Following the method as described on the wikipedia page, the Lagrangian function is:
$$
\mathcal{L}(\mathbf{p_0},...,\mathbf{p_7},\lambda_0,...,\lambda_5) = f(\mathbf{p_0},...\mathbf{p_7}) - \sum{\lambda_j g_j(\mathbf{p_0},...,\mathbf{p_7})}
$$
The solution will be a stationary point of $\mathcal{L}$, i.e. a point at which all 30 scalar partial derivatives in the gradient of $\mathcal{L}$ are zero. This is a system of 30 equations in 30 scalar unknowns.
Expanding the first three of these partial derivatives which we want to be zero,
$\frac{\partial \mathcal{L}}{\partial \mathbf{p_0}} = \left(\frac{\partial \mathcal{L}}{\partial x_0},
\frac{\partial \mathcal{L}}{\partial y_0},
\frac{\partial \mathcal{L}}{\partial z_0}\right)$, as an example of how it looks:
$$\begin{aligned}
\frac{\partial \mathcal{L}}{\partial \mathbf{p_0}}
&= \frac{\partial f}{\partial \mathbf{p_0}} - \sum{\lambda_j \frac{\partial g_j}{\partial \mathbf{p_0}}} \\
&= \frac{\partial f}{\partial \mathbf{p_0}} - \lambda_0 \frac{\partial g_0}{\partial \mathbf{p_0}}
- \lambda_1 \frac{\partial g_1}{\partial \mathbf{p_0}}
- \lambda_2 \frac{\partial g_2}{\partial \mathbf{p_0}}
\text{ (since }g_3,g_4,g_5\text{ do not depend on }\mathbf{p_0}\text{)} \\
&= 2\left(\mathbf{p_0} {-} \mathbf{\tilde{p_0}}\right)
- \lambda_0 (\mathbf{p_3}{-}\mathbf{p_1}){\times}(\mathbf{p_2}{-}\mathbf{p_1})
- \lambda_1 (\mathbf{p_5}{-}\mathbf{p_4}){\times}(\mathbf{p_1}{-}\mathbf{p_4})
- \lambda_2 (\mathbf{p_6}{-}\mathbf{p_2}){\times}(\mathbf{p_4}{-}\mathbf{p_2})
\end{aligned}$$
And expanding $\frac{\partial \mathcal{L}}{\partial \lambda_5}$ as another representative example:
$$\begin{aligned}
\frac{\partial \mathcal{L}}{\partial \lambda_0} &= -g_0(\mathbf{p_0},...,\mathbf{p_7}) \\
&= - ((\mathbf{p_2}-\mathbf{p_0})\times(\mathbf{p_3}-\mathbf{p_0}))\cdot(\mathbf{p_1}-\mathbf{p_0})
\end{aligned}$$
Here is the full system of $8{\times}3{+}6{=}30$ polynomial equations in the 30 unknowns, expanded(ish). (There are probably typos.)
$$\begin{aligned}
\frac{\partial \mathcal{L}}{\partial \mathbf{p_0}} &{=} 2\left(\mathbf{p_0} {-} \mathbf{\tilde{p_0}}\right)
{-} \lambda_0 (\mathbf{p_3}{-}\mathbf{p_1}){\times}(\mathbf{p_2}{-}\mathbf{p_1})
{-} \lambda_1 (\mathbf{p_5}{-}\mathbf{p_4}){\times}(\mathbf{p_1}{-}\mathbf{p_4})
{-} \lambda_2 (\mathbf{p_6}{-}\mathbf{p_2}){\times}(\mathbf{p_4}{-}\mathbf{p_2})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_1}} &{=} 2\left(\mathbf{p_1} {-} \mathbf{\tilde{p_1}}\right)
{-} \lambda_0 (\mathbf{p_2}{-}\mathbf{p_0}){\times}(\mathbf{p_3}{-}\mathbf{p_0})
{-} \lambda_1 (\mathbf{p_4}{-}\mathbf{p_5}){\times}(\mathbf{p_0}{-}\mathbf{p_5})
{-} \lambda_3 (\mathbf{p_7}{-}\mathbf{p_5}){\times}(\mathbf{p_3}{-}\mathbf{p_5})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_2}} &{=} 2\left(\mathbf{p_2} {-} \mathbf{\tilde{p_2}}\right)
{-} \lambda_0 (\mathbf{p_1}{-}\mathbf{p_3}){\times}(\mathbf{p_0}{-}\mathbf{p_3})
{-} \lambda_2 (\mathbf{p_4}{-}\mathbf{p_0}){\times}(\mathbf{p_6}{-}\mathbf{p_0})
{-} \lambda_4 (\mathbf{p_7}{-}\mathbf{p_3}){\times}(\mathbf{p_6}{-}\mathbf{p_3})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_3}} &{=} 2\left(\mathbf{p_3} {-} \mathbf{\tilde{p_3}}\right)
{-} \lambda_0 (\mathbf{p_0}{-}\mathbf{p_2}){\times}(\mathbf{p_1}{-}\mathbf{p_2})
{-} \lambda_3 (\mathbf{p_5}{-}\mathbf{p_7}){\times}(\mathbf{p_1}{-}\mathbf{p_7})
{-} \lambda_4 (\mathbf{p_6}{-}\mathbf{p_2}){\times}(\mathbf{p_7}{-}\mathbf{p_2})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_4}} &{=} 2\left(\mathbf{p_4} {-} \mathbf{\tilde{p_4}}\right)
{-} \lambda_1 (\mathbf{p_1}{-}\mathbf{p_0}){\times}(\mathbf{p_5}{-}\mathbf{p_0})
{-} \lambda_2 (\mathbf{p_2}{-}\mathbf{p_6}){\times}(\mathbf{p_0}{-}\mathbf{p_6})
{-} \lambda_5 (\mathbf{p_7}{-}\mathbf{p_6}){\times}(\mathbf{p_5}{-}\mathbf{p_6})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_5}} &{=} 2\left(\mathbf{p_5} {-} \mathbf{\tilde{p_5}}\right)
{-} \lambda_1 (\mathbf{p_0}{-}\mathbf{p_1}){\times}(\mathbf{p_4}{-}\mathbf{p_1})
{-} \lambda_3 (\mathbf{p_3}{-}\mathbf{p_1}){\times}(\mathbf{p_7}{-}\mathbf{p_1})
{-} \lambda_5 (\mathbf{p_6}{-}\mathbf{p_7}){\times}(\mathbf{p_4}{-}\mathbf{p_7})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_6}} &{=} 2\left(\mathbf{p_6} {-} \mathbf{\tilde{p_6}}\right)
{-} \lambda_2 (\mathbf{p_0}{-}\mathbf{p_4}){\times}(\mathbf{p_2}{-}\mathbf{p_4})
{-} \lambda_4 (\mathbf{p_3}{-}\mathbf{p_7}){\times}(\mathbf{p_2}{-}\mathbf{p_7})
{-} \lambda_5 (\mathbf{p_5}{-}\mathbf{p_4}){\times}(\mathbf{p_7}{-}\mathbf{p_4})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \mathbf{p_7}} &{=} 2\left(\mathbf{p_7} {-} \mathbf{\tilde{p_7}}\right)
{-} \lambda_3 (\mathbf{p_1}{-}\mathbf{p_3}){\times}(\mathbf{p_5}{-}\mathbf{p_3})
{-} \lambda_4 (\mathbf{p_2}{-}\mathbf{p_6}){\times}(\mathbf{p_3}{-}\mathbf{p_6})
{-} \lambda_5 (\mathbf{p_4}{-}\mathbf{p_5}){\times}(\mathbf{p_6}{-}\mathbf{p_5})
{=} (0,0,0) \\
\frac{\partial \mathcal{L}}{\partial \lambda_0} &= - ((\mathbf{p_2}-\mathbf{p_0})\times(\mathbf{p_3}-\mathbf{p_0}))\cdot(\mathbf{p_1}-\mathbf{p_0}) = 0 \\
\frac{\partial \mathcal{L}}{\partial \lambda_1} &= - ((\mathbf{p_1}-\mathbf{p_0})\times(\mathbf{p_5}-\mathbf{p_0}))\cdot(\mathbf{p_4}-\mathbf{p_0}) = 0 \\
\frac{\partial \mathcal{L}}{\partial \lambda_2} &= - ((\mathbf{p_4}-\mathbf{p_0})\times(\mathbf{p_6}-\mathbf{p_0}))\cdot(\mathbf{p_2}-\mathbf{p_0}) = 0 \\
\frac{\partial \mathcal{L}}{\partial \lambda_3} &= - ((\mathbf{p_5}-\mathbf{p_7})\times(\mathbf{p_1}-\mathbf{p_7}))\cdot(\mathbf{p_3}-\mathbf{p_7}) = 0 \\
\frac{\partial \mathcal{L}}{\partial \lambda_4} &= - ((\mathbf{p_3}-\mathbf{p_7})\times(\mathbf{p_2}-\mathbf{p_7}))\cdot(\mathbf{p_6}-\mathbf{p_7}) = 0 \\
\frac{\partial \mathcal{L}}{\partial \lambda_5} &= - ((\mathbf{p_6}-\mathbf{p_7})\times(\mathbf{p_4}-\mathbf{p_7}))\cdot(\mathbf{p_5}-\mathbf{p_7}) = 0 \\
\end{aligned}$$
(Notice that the last six of them just re-state the six coplanarity constraints.)
At this point, I'm not sure how to proceed.
It seems like we've probably made some progress, compared to the original minimization problem, but I don't see how to solve this system of 30 degree-3 polynomials in 30 unknowns (other than by using a numeric solver; Newton's method would probably work well for this).