In triangle $ABC,$ altitudes $\overline{AD}$ and $\overline{BE}$ intersect at $H$. If $\angle BAC = 40^\circ$ and $\angle ABC = 40^\circ$, then what is $\angle AHB$?

Since $\overline{AD}$ and $\overline{BE}$ are perpendiculars to their respective bases, triangle $ABC$ is an isosceles triangle by a theorem derived from the Pythagorean Theorem. Hence, $\angle BCA = \angle ABC = 40^\circ,$ so

\[\angle ACB = 180^\circ - 2 \cdot 40^\circ = 100^\circ.\]Therefore, $\angle AHB = \angle ACB = \boxed{100^\circ}.$ [asy]
import olympiad; import cse5; size(150); defaultpen(linewidth(0.8));
dotfactor=4;
pair B=(0,0), C=1*dir(60), A=C+dir(180-40+60*dir(0));
pair D=foot(A,B,C), E=foot(B,A,C), H=extension(A,D,B,E);
draw(A--B--C--cycle^^A--D^^B--E);
draw(A--H--B^^C--H,dashed);
label("$A$",A,NE);
label("$B$",B,SW);
label("$C$",C,N);
label("$D$",D,S);
label("$E$",E,SE);
label("$H$",H,NE);
[/asy]

Since $\overline{AD}$ is an altitude of triangle $ABC$, $\angle CAD$ is a right angle. Also, since $\angle BAC = 40^\circ$, then $\angle CAD = 90^\circ - \angle BAC = 90^\circ - 40^\circ = 50^\circ$.

Since $\angle ABC = 40^\circ$ and $\angle AHB$ is a straight angle, then $\angle AHG = 180^\circ - \angle ABC = 180^\circ - 40^\circ = 140^\circ$.

Since $\angle AHB$ and $\angle AHG$ are adjacent angles this means that $\angle AHB + \angle AHG = 180^\circ$. So, $\angle AHB + 140^\circ = 180^\circ$. Subtracting 140 on both sides gives us $\angle AHB = \boxed{40^\circ}$.