It's mostly genetics.
The only thing I've heard can make a difference (and I can't confirm if this is accurate) is heat. Supposedly, the more heat you trap on your head, the faster your hair MAY fall out if it's already falling out. So, if you think you're doing well by wearing a hat to hide a receding hair line, you might be speeding it up.
As for gray hair, sometimes grays come in early as a result of a copper deficiency. Again, genetics have a strong play here, but you could try eating a bit more copper if you are going gray early.