As you're reading these chapters which cover the account of Joseph and his experience in Egypt, remember that Paul told us in 1 Corinthians that the Old Testament was written for our instruction.
Genesis 38 - God's hand on the genealogy of Christ is seen by not allowing any Canaanite to be a part of it. It's sad to see both Tamar and Judah lower themselves to such moral depths, but the offspring of this incest was still used of God to connect the line of Abraham to Christ.
Genesis 39 - Joseph is seen in such contrast to Judah of chapter 38. Though tempted to sin Joseph was willing to suffer imprisonment rather than offend his God.
Genesis 40 - You never know who the Lord will bring into your life nor the impact an experience in one place will play a huge roll in another place. Joseph met the cupbearer and the chief baker of Pharaoh in prison. He would interpret their dreams and his prophecy would be fulfilled. Though the cupbearer did not remember Joseph to seek his release he would eventually be used to bring Joseph before Pharaoh.