How can we avoid becoming self-righteous?

By recognizing that all the virtue, character, and goodness in us is a gift of God by grace alone provided by the mercy found in Christ alone.

“For who regards you as superior? What do you have that you did not receive? And if you did receive it, why do you boast as if you had not received it?” (1 Corinthians 4:7)