Considering that the distance to the near plane (the adjacent side to the FOV angle) stays the same, but the other side (the opposite side from the FOV angle) changes by a ratio of width/height, the tangents must also vary by that same ratio (since tan = opposite/adjacent, and opposite changes)
Therefore, you end up with:
horizontalFov = atan( tan(verticalFov) * width/height )verticalFov = atan( tan(horizontalFov) * height/width )
Though, for most screen aspect ratios, simply using
horizontalFov = verticalFov * width/heightverticalFov = horizontalFov * height/width
is a really close approximation.