Two goals each from Konstantinos Mavropanos and Taty Castellanos saw the Hammers move out of the relegation zone for the first time since December.