How is the wind direction and wind speed measured in flight?
Indirectly, as the difference between true air speed and ground speed.
Since aircraft cannot measure true air speed, several steps are needed to arrive at the correct wind speed:

The pitot tube (big aircraft have several of them) gives the stagnation pressure of the air, which is the sum of static and dynamic pressure.
The static ports (again, big aircraft have several of them) give the static pressure of the ambient air, so the dynamic pressure can be isolated.
With the static pressure and the ambient temperature the air density can be calculated.
With the density it is now possible to calculate the true air speed from the dynamic pressure.
From the compass you get the heading of the aircraft, so you know the direction of the true air speed.
The ground speed and track direction can be calculated by repeatedly measuring the location of the aircraft and dividing the distance by the time between measurements, or with modern aircraft it can be read directly from the GPS display.
Wind speed and direction can be calculated by subtracting the true air speed vector from the ground speed vector.

You will notice that there are a lot of possible sources of error in this procedure. All instruments involved have their own bias and scaling error. However, if everything is carefully calibrated and corrected, the result can be very accurate.