Genesis 6:9 (KJV) says,
Noah was a just man and perfect in his generations, and Noah walked with God.
But then Genesis 9:21 (KJV) recounts an unsavory affair,
[Noah] planted a vineyard: And he drank of the wine, and was drunken; and he was uncovered within his tent.
It's by no means the worst offense recorded in the bible, but it does run counter to the idea that "Noah was a just man." How do we reconcile those seemingly conflicting verses?
Well, Noah had already gained God's favor not by his perfect behavior, but rather by his faith. Genesis 8:20-21 (KJV) says,
And Noah builded an altar unto the Lord; and took of every clean beast, and of every clean fowl, and offered burnt offerings on the altar. And the Lord smelled a sweet savour.
The phrase "smelled a sweet savour" implies that God approved of Noah's offering. And Noah offered those sacrifices as a faithful show of gratitude toward God.
The same applies to us. We are "just" before God not because we're good, but rather because God has declared us just. Thankfully, we no longer have to offer animal sacrifices to show our gratitude for that. Jesus took care of that once and for all. Instead, as we are instructed in 1 Samuel 15:22 (KJV),
To obey is better than sacrifice, and to hearken than the fat of rams.