Legacy is what someone leaves behind them, either when they leave a place or when they die.
"the legacy of the ancient philosophers"
Someone's heritage is something transmitted to them or acquired by them from a predecessor, whether this is a material possession, a tradition, a characteristic or whatever. Heritage = that which has been inherited (it can also be described as a birthright)
"a heritage of poverty and suffering"
"a national heritage of honor, pride, and courage"
Inheritance = heritage, but where heritage can be used to describe someone's roots in terms of history, personality traits, background or traditions, inheritance is generally concerned with material possessions.
"His inheritance comprised a large country estate and several cars"