What Paul is saying is that Abraham believed that God would make his son his heir and that he would become the first of millions of offspring. He was effectively believing that God would be faithful to the promise he had made, and that God responded by crediting him righteousness, i.e., accrediting to him the status of what he was to become, the head of a redeemed covenant community.
If this understanding is correct, then both Genesis and Paul see that the primary issue that Gen.15:6 is dealing with, is Yahweh’s acceptance of Abraham. It is to do with God committing himself to Abraham in covenant that He would act righteously toward Abraham, always keeping faith with His promise. Abraham's faith was his response to the promise that Yahweh had given him, it was his: ‘Amen, I want to be part of your covenant’. In so responding, Yahweh dealt with him in righteousness; he was the object of the covenant promises.
The matter of Abraham’s sin and its forgiveness is secondary, even though still very important. No covenant with Yahweh could be established without a proper dealing with sin. For the covenant to be established and ratified it is implied that the sin of Abraham has been dealt with. But again, to make that the primary issue of the passage is to miss the clear covenantal significance of what is happening.
Holland, Tom. Contours of Pauline Theology. London, UK: Christian Focus Publications, 2004. 215. (paragraphing mine)