Later on we'll see the reconciliation of Joseph to his brothers. Another example of the importance of not hanging the past over the heads of your siblings. They often change over time and reconciliation/forgiveness should always be sought among family.
These two chapters serve as the set-up for the great things God will do through Joseph. I really think their primary purpose is to establish the wickedness of Joseph's brothers, especially Judah. It was Judah's idea to sell Joseph into slavery. Chapter 38 tell us more of Judah's wicked behavior towards his own family.