The answer to this question involves quite a bit of spherical trigonometry. Call $(\lambda_1,\varphi_1)$ the longitude and latitude of the place of departure, and $(\lambda_2,\varphi_2)$ the coordinates of the destination. Let's assume that the plane travels along a great circle. Then it will travel a total angle $\theta$, given by
$$
\cos\theta = \sin\varphi_1\sin\varphi_2 + \cos\varphi_1\cos\varphi_2\cos(\lambda_2-\lambda_1).
$$
If $\theta$ is expressed it radians, then the corresponding distance is $D=\theta R_\oplus$, with $R_\oplus$ the radius of the Earth. Suppose that the total flight time is $T$, and that the plane flies at a constant speed. If $t$ is the time since take-off, then
$$
\begin{align}
\theta_1 &= \theta t/T,\\
\theta_2 &= \theta -\theta_1,
\end{align}
$$
where $\theta_1$ is the angle traveled by the plane at time $t$, while $\theta_2$ is the angle that the plane still has to travel. At time $t$, the plane will then be above the location $(\lambda,\varphi)$, given by
$$
\begin{align}
\cos\theta_1 &= \sin\varphi_1\sin\varphi + \cos\varphi_1\cos\varphi\cos(\lambda-\lambda_1),\\
\cos\theta_2 &= \sin\varphi_2\sin\varphi + \cos\varphi_2\cos\varphi\cos(\lambda-\lambda_2),
\end{align}
$$
from which $(\lambda(t),\varphi(t))$ can be derived (after some tedius calculations).
If we know the Greenwhich Mean Solar Time $t_0$ at the moment of departure, then we can obtain the hour angle $H_\odot(t)$ of the Sun at $(\lambda(t),\varphi(t))$:
$$
H_\odot(t) + 12^\text{h}=t_0 +t + \lambda(t)\qquad\text{(modulo $24^\text{h}$)},
$$
where all variables are expressed in hours, minutes, and seconds (and $360^\circ$ corresponds with $24^\text{h}$). We also need to know the declination of the Sun $\delta_\odot$ during the flight (so we need to know the date).
The altitude of the Sun $a_\odot(t)$ above the local horizon is then
$$
\sin a_\odot(t) = \sin\varphi(t)\sin\delta_\odot + \cos\varphi(t)\cos\delta_\odot \cos H_\odot(t)
$$
(see the wiki page on celestial coordinates). Sunset and sunrise correspond with $a_\odot=0^\circ$ on the ground (ignoring atmospheric refraction). Using simple trigonometry, it is easy to show that from the plane's perspective, at a height $h$, sunset and sunrise will occur when
$$a_\odot= -\cos^{-1}(R_\oplus/(R_\oplus+h)).$$