In order to get that "optimal" line, the key is to establish the objective functions. In order to determine a line in 3D, we need to determine a point $p\in\mathbb{R}^3$ on this line, and the vector $v\in\mathbb{R}^3$ which is parallel to the line.
Next I will first determine the optimal $p$ and then the optimal $v$.
Step 1: determine $p$
It is natural to choose $p$ as the point that is closest to all of the planes.
For plane $i$, denote $n_i\in\mathbb{R}^3$ and $o_i\in\mathbb{R}^3$ respectively as its normal vector and a point on the plane. Then the distance between a point $p$ and the plane can be expressed as
$$\left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right)(p-o_i)\right\|$$
Hence to determine the point $p$, we can minimize the objective function
$$J_p= \sum_{i=1}^n \left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right)(p-o_i)\right\|^2 $$
Denote $P_i=\frac{n_i n_i^T}{n_i^Tn_i}$, then $J_p$ can be written as
$$ J_p=\sum_{i=1}^n (p-o_i)^T P_i (p-o_i) $$
Note $P_i$ is an orthogonal projection matrix satisfying $P_i=P_i^T$ and $P_i^2=P_i$. A short calculation shows that
$$ p^* = \left(\sum_{i=1}^n P_i\right)^{-1}\left(\sum_{i=1}^nP_io_i\right)$$
You can check the condition under which $\sum_{i=1}^n P_i$ is invertible.
Step 2: determine $v$
Intuitively speaking, the angle between the vector $v$ and a plane should be as small as possible. In other words, $v$ should be perpendicular to the normal vector $n_i$ as much as possible. Or we can say the orthogonal projection of $v$ on $n_i$ should as small as possible. Note we only need to determine the direction of $v$. Hence we can assume $v^Tv=1$.
To determine $v$ we can minimize the objective function
$$ J_v= \sum_{i=1}^n \left\|\left(\frac{n_i n_i^T}{n_i^Tn_i}\right) v \right\|^2 = v^T \left(\sum_{i=1}^n P_i\right) v$$
Denote $A=\sum_{i=1}^n P_i $. Clearly $A$ is positive definite (you need to check under what condition $A$ is invertible). Let the SVD of $A$ be $A=U\Lambda U^T$. Hence
$$ J_v=v^T A v \ge \lambda_{\mathrm{min}}(A) v^T v = \lambda_{\mathrm{min}}(A)$$
where the equality holds when $v$ is the last column of $U$.