What factors are involved in determining the spanwise pitching moment distribution?
In order to answer this question you need to know the detailed construction of the wing. In particular, the elastic center of each wing section is important. A simple way to find it would be to cut a cardboard into the cross section of the wing. Adjust local thickness according to skin panel thickness. Now find the center of gravity of this piece of cardboard, and you know where the elastic center is. Note that this only works for a closed torsion box; open sections tend to have their elastic center outside of their circumference.

The Free Dictionary has this definition for the elastic center:


  A point within a wing section at which application of a concentrated
  load will cause the wing to deflect without rotation. This is the
  point in the wing section at which rotation will occur when the wing
  is subjected to a twist.


Now you need to calculate the distance between the elastic center and the quarter point, around which the pitch moment coefficient is defined. This, multiplied by the local lift coefficient, will give you the offset moment which you need to add to the pitch moment in order to calculate the total moment twisting the wing.


  Which point on the section of the aerofoil would I take moments about?


That depends what moments you want to know. Aerodynamic moments are defined around the quarter point. If you want to calculate the aeroelastic twist of the wing, you need to use the elastic center.


  Would the weight of an engine produce a pitching moment and hence
  affect the pitching moment distribution?


Masses produce moments which depend on load factor while aerodynamic forces depend on dynamic pressure. Yes, you need to add masses and their moments around the elastic center, and you need to do this separately for each speed at which you do the calculation.