The profit is
π(p)=(p−6)⋅8000(1−40p)=200(p−6)(40−p),
a downward parabola vanishing at p=6 and p=40. The maximum is at the vertex, midway between the zeros:
p∗=26+40=23 €.
At that price D(23)=8000(1−4023)=3400 units and the profit is (23−6)⋅3400=57800 €.