What do I do with the neutral and ground when wiring a transfer switch?
There can only be one point in the system where neutral and ground wires are joined, and this is usually in the main panel.  Therefore, you must lift the bond from the generator, or disconnect the ground wire from the generator to the transfer switch.

If you lift the bond on the generator, you can run both ground and an insulated neutral back to the transfer switch.  You will also run ground and insulated neutral from the main panel to the transfer switch, and ground and insulated neutral to the subpanel from the transfer switch.  Note that neither neutral nor ground are switched in the transfer switch.  The generator can optionally be grounded to a rod.

If you cannot lift the bond, disconnect the ground wire to the transfer switch at the generator (or don't run a ground wire at all).  The subpanel will still be grounded from the unswitched ground wire from the main panel.  The generator cannot be grounded to a rod because this would tie the neutral to ground in a second location through the bond.