$\DeclareMathOperator{\acos}{acos}$To keep things general for both clarity and flexibility, let's write $A$ for the angle of inclination of a face ($30$ degrees in the question) and $D$ for the flat angle at the top inside of the joint ($90$ degrees in the question). Finally, let $w$ denote the width of an uncut board.
Formulas In a coordinate system whose origin is the vertex of the angle marked $D/2$ and with the top edge of one board along the $x$-axis, the top joined edge of the mitered boards points in the direction
$$
v = (w\cos A \cot(D/2), w\cos A, w\sin A)
= w(\cos A \cot(D/2), \cos A, \sin A).
$$
Consequently, $B$ is the angle between $v$ and $w(0, \cos A, \sin A)$,
$$
B = \acos\biggl[\frac{1}{\sqrt{1 + \cos^{2} A \cot^{2}(D/2)}}\biggr].
$$
For $D = 90$ degrees (four boards making a mitered rectangular frame) we have $\cot(D/2) = 1$ and the preceding formula simplifies to
$$
B = \acos\biggl[\frac{1}{\sqrt{1 + \cos^{2} A}}\biggr].
$$
The miter angle $E$ for the cut end is given by
$$
E = \acos\Bigl[\sqrt{\sin^{2}(D/2) + \cos^{2} A \cos^{2}(D/2)}\Bigr].
$$
For $A = 30$ degrees (and $D = 90$ degrees), $\cos A = \sqrt{3}/2$, $\sin A = 1/2$, and $\cos^{2}(D/2) = \sin^{2}(D/2) = 1/2$, so
$$
B = \acos \sqrt{4/7} \approx 40.9\ \text{degrees},\qquad
E = \acos \sqrt{7/8} \approx 20.7\ \text{degrees}.
$$
That is, the blade of a miter saw needs to be turned $40.9$ degrees from perpendicular and tilted $20.7$ degrees from vertical.
Derivations Vector algebra is a convenient tool for this type of calculation. Derivation of these formulas follows.
For completeness (possibly reiterating things you know):
An ordered triple $v = (x, y, z)$ can represent either a displacement between two points, or the location of a point relative to an origin.
The dot product of two triples $v_{1} = (x_{1}, y_{1}, z_{1})$ and $v_{2} = (x_{2}, y_{2}, z_{2})$ is the number
$$
v_{1} \cdot v_{2} = x_{1}x_{2} + y_{1}y_{2} + z_{1}z_{2}.
$$
The length of an ordered triple is
$$
|v| = \sqrt{v \cdot v} = \sqrt{x^{2} + y^{2} + z^{2}}.
$$
The dot product and length formulas do not depend on angle units.
The angle $\theta$ between two non-zero vectors satisfies $v_{1} \cdot v_{2} = |v_{1}|\, |v_{2}| \cos\theta$, or
$$
\theta = \acos\frac{v_{1} \cdot v_{2}}{|v_{1}|\, |v_{2}|}.
$$
Usually mathematicians measure angles in radians, and $\acos$ refers to the "radian-valued" inverse cosine. A calculator in degrees mode will calculate angles in degrees.
The cross product of two triples $v_{1} = (x_{1}, y_{1}, z_{1})$ and $v_{2} = (x_{2}, y_{2}, z_{2})$,
$$
v_{1} \times v_{2} = (y_{1}z_{2} - y_{2}z_{1}, x_{3}z_{1} - x_{1}z_{3}, x_{1}y_{2} - x_{2}y_{1}),
$$
is orthogonal to both factors. (Its magnitude is unneeded here, but turns out to be $|v_{1}|\, |v_{2}| \sin\theta$.)
The diagram shows the top surfaces of the mitered boards. The right triangle with angle marked $A$ has hypotenuse $w$, so its sides are $w\cos A$ and $w\sin A$ as marked. Place the origin as shown, at the vertex of a right triangle with angle $D/2$. The side of this triangle along the $x$-axis is $(w\cos A)\cot(D/2)$, so
$$
v = w(\cos A \cot(D/2), \cos A, \sin A)
$$
as claimed. The magnitude $|v| = w\sqrt{1 + \cos^{2} A \cot^{2}(D/2)}$ may be used as a consistency check to measure the length of the mitered edge before cutting.
The vector perpendicularly across the board is $w(0, \cos A, \sin A)$. The angle $B$ between $v$ and this vector may be calculated using dot products and the scaled vectors $(\cos A \cot(D/2), \cos A, \sin A)$ and $(0, \cos A, \sin A)$, yielding:
\begin{align*}
\cos B &= \frac{v \cdot (0, \cos A, \sin A)}{|v|} \\
&= \frac{1}{\sqrt{1 + \cos^{2} A \cot^{2}(D/2)}}.
\end{align*}
To calculate the angle $E$ between a vertical cut and the board's mitered end, we'll calculate unit normal vectors to the uncut vertical end and mitered end of the board.
The plane of the uncut end of the board contains $v$ and $n = (0, -\sin A, \cos A)$, a unit normal to the face of the board. A short calculation gives
\begin{align*}
v \times n &= w(1, -\cos^{2} A \cot(D/2), -\cos A \sin A \cot(D/2)), \\
|v \times n| &= w\sqrt{1 + \cos^{2} A \cot^{2}(D/2)}.
\end{align*}
The plane of the cut end of the board contains $v$ and $k = (0, 0, 1)$. A short calculation gives
\begin{align*}
v \times k &= w(\cos A, -\cos A \cot(D/2), 0) = w\cos A(1, -\cot(D/2), 0), \\
|v \times k| &= w\cos A \sqrt{1 + \cot^{2}(D/2)} = w\cos A \csc(D/2).
\end{align*}
Consequently,
\begin{align*}
\cos E &= \frac{v \times n}{|v \times n|} \cdot \frac{v \times k}{|v \times k|} \\
&= \frac{1 + \cos^{2} A \cot^{2}(D/2)}{\csc(D/2)\sqrt{1 + \cos^{2} A \cot^{2}(D/2)}}.
\end{align*}
Multiplying and dividing by $\sin^{2}(D/2)$ and simplifying gives
$$
E = \acos\Bigl[\sqrt{\sin^{2}(D/2) + \cos^{2} A \cos^{2}(D/2)}\Bigr].
$$