Sorry for the late answer.
Basically, just work your way backwards. Equation form of the question:
x * 2/3 * 1/8 = $40
where x is the amount earned before taxes. Therefore, after rearranging some stuff, we get:
x = $40 * 8 * 1.5
and thus
x = $320 * 1.5
x = $480