How can the wind speed and direction be calculated from on-board measurements?
With the set of parameters available to you, you cannot do this. 

If you have the actual track instead of the desired track, you will be able to calculate the wind. 

The simplest way to do this is using vector math. 

There are three vectors to consider:


ground speed vector $\vec{V_{gs}}$
air speed vector $\vec{V_{as}}  $
wind speed vector $\vec{V_{ws}}  $




$\vec{V_{gs}} =\vec{V_{as}} +  \vec{V_{ws}}  $

$\vec{V_{ws}} = \vec{V_{gs}}  - \vec{V_{as}}  $

I assume the actual track angle ($\phi$) and heading ($\psi$) are with respect to the true North. 

The north component of your air speed is then: $V_{as} \cdot \cos(\psi)$ and the east component of your air speed is: $V_{as} \cdot \sin(\psi)$

For ground speed the decomposition is: north: $V_{gs} \cdot \cos(\phi)$ and the east component of your ground speed is: $V_{gs} \cdot \sin(\phi)$

$$\begin{bmatrix}
       V_{ws,north}\\
       V_{ws,east}
        \end{bmatrix} = \begin{bmatrix}
      V_{gs} \cdot \cos(\phi) - 
      V_{as} \cdot \cos(\psi) \\
      V_{gs} \cdot \sin(\phi) - 
      V_{as} \cdot \sin(\psi)        \end{bmatrix}$$ 

You now have the north and east component of the wind vector. This you can change to a speed and direction, but I leave that last part up to you. Don't forget that wind direction is usually reported as the direction from which the wind is coming. 



To find the wind speed from the North and East components use the root of the sum of the squares:

$V_{ws}=\sqrt{V_{ws,north}^2 +
       V_{ws,east}
^2}$

The wind direction can be found by

$\tan^{-1} (\frac {V_{ws,north}}{V_{ws,east} }) $

Note that this will give a division by 0 for winds exactly from north or south.

To implement it in a computer language the atan2 function can be used. This prevents division by zero and also returns the direction of the full range of the circle instead of semi-circular 

wind_dir = atan2(-wind_north, -wind_east)

This should give the direction from which the wind is coming in radians.