<s>[INST] How to find the "most upright" orthogonal vector to another vector? Given an arbitrary vector, I can find any orthogonal vector by solving $ax + by + cz = 0$. 
I want to find the "most upright" orthogonal (unit) vector, where $z$ is maximized. There must be a straightforward closed form solution to this, right?
 [/INST] Restating your problem (and adding a condition), you are given a vector $\vec{v}=\langle a,b,c\rangle$ and you want to find a vector $\vec{w}=\langle x,y,z\rangle$ so that


*

*$\vec{w}\cdot\vec{v}=0$,

*$\|\vec{w}\|=1$

*$\vec{w}\cdot\vec{e}_3$ is maximized


As you state, you want to maximize $z$ subject to
\begin{align*}
ax+by+cz&=0\\
x^2+y^2+z^2&=1
\end{align*}
Perhaps a Lagrange multiplier approach would be good here:
\begin{align*}
0&=\lambda a+2\mu x\\
0&=\lambda b+2\mu y\\
1&=\lambda c+2\mu z\\
0&=ax+by+cz\\
1&=x^2+y^2+z^2
\end{align*}
We should really assume that $a$ and $b$ are not both zero because otherwise $\vec{v}$ points vertically and there are no orthogonal, upward pointing vectors.


*

*If $\mu=0$, then we get that $\lambda=\frac{1}{c}$ (and $c\not=0$), but then the first two equations are $0=\frac{a}{c}$ and $0=\frac{b}{c}$, so $a=0=b$  This contradicts our assumption, so we're ok here.

*If $\mu\not=0$, then we can solve for $x$, $y$, and $z$:
\begin{align*}
x&=-\frac{\lambda a}{2\mu}\\
y&=-\frac{\lambda b}{2\mu}\\
z&=\frac{1-\lambda c}{2\mu}
\end{align*}
We can substitute these into the fourth equation (and cancel the $2\mu$'s) to get
$$
-\lambda a^2-\lambda b^2-\lambda c^2+c=0.
$$
Now, we make things simpler by adding the assumption that $\langle a,b,c\rangle $ is a unit vector, so we could rewrite this equation as $c=\lambda$.  If not, we use $c=\lambda\|\vec{v}\|$ throughout the rest of this problem.
Therefore,
\begin{align*}
x&=-\frac{ac}{2\mu}\\
y&=-\frac{bc}{2\mu}\\
z&=\frac{1-c^2}{2\mu}
\end{align*}
Substituting all of this into the final equation gives
$$
4\mu^2=a^2c^2+b^2c^2+1-2c^2+c^4=(a^2+b^2+c^2)c^2+1-2c^2.
$$
Therefore
$$
4\mu^2=1-c^2
$$
or
$$
\mu=\pm\sqrt{\frac{1-c^2}{4}}
$$
Substituting these into the formulae for $x,y,z$ gives that 
\begin{align*}
x&=\mp\frac{ac}{\sqrt{1-c^2}}\\
y&=\mp\frac{bc}{\sqrt{1-c^2}}\\
z&=\pm\frac{1-c^2}{\sqrt{1-c^2}}
\end{align*}
Depending on the signs, you should get the largest and smallest that $z$ could be (provided I made no errors).
</s>