Workers have voted overwhelmingly to accept pay offers from train companies and Network Rail.