Scripture presents two kinds of righteousness: positional & practical. 

Positional Righteousness

Positional righteousness is Jesus' righteousness that we receive from Him by faith. You can think of it as a vertical righteousness between you and God. Luther called it an “alien righteousness.” Luther didn't mean that it comes from outer space; he meant that it comes to us from outside ourselves. We can't produce this righteousness. We are dead in sin. So Christ obtains this righteousness for us. Luther said, “It is through faith in Christ that Christ’s righteousness becomes our righteousness.” 

Positional righteousness is not earned, it is given. It's a free gift that we receive through faith in Christ.

Scriptural examples:

For our sake he made him to be sin who knew no sin, so that in him we might become the righteousness of God.(2 Cor 5:21).

“And to the one who does not work but believes in him who justifies the ungodly, his faith is counted as righteousness” (Rom 4:4-5).

“. . . that I may gain Christ and be found in him, not having a righteousness of my own that comes from the law, but that which comes through faith in Christ, the righteousness from God that depends on faith(Phil 3.8-9).

Practical Righteousness

Practical righteousness is the fruit of positional righteousness. You can think of it as a horizontal righteousness between you and your neighbor. It is acting in gentleness and love, doing works of service, etc. 

Scriptural examples:

“Be completely humble and gentle; be patient, bearing with one another in love” (Eph 4:2).

"Be kind and compassionate to one another, forgiving each other, just as in Christ forgave you" (Eph 4:32).

“Make sure that nobody pays back wrong for wrong, but always strive to do what is good for each other and for everyone else” (1 Thes 5:15).

How They Relate

Most people confuse the two kinds of righteousness with each other, which causes much anxiety and/or self-righteousness. We must instead keep them separate and distinct. As Egon warns in Ghostbusters: "Never cross the streams!" 

This is critically important.

Our practical (horizontal) righteousness never has any effect on our positional (vertical) righteousness, one way or the other. We've been gifted Jesus’ perfect righteousness and can neither diminish it nor improve upon it. Ever. It's permanent. 

Therefore, we must see that our good works don't merit us anything with God, and our failures to do good works don't take anything away from us. As Luther rightly points out: “God doesn’t need our good works, our neighbor does.” Practical righteousness is not for God. How could it be? In His eyes we have Jesus' perfect righteousness. Practical righteousness is instead for our neighbor, that he might see our good works and worship God (Mat 5:16).

BUT! Though the horizontal never effects the vertical, the vertical has a profound and automatic effect on the horizontal. The extravagant grace showered on us by Christ will naturally have a positive impact on the way we treat our neighbor. 

"But by the grace of God I am what I am, and his grace to me was not without effect. No, I worked harder than all of them—yet not I, but the grace of God that was with me" (1 Cor 15:10).