Both of these two terms refer to white people who were connected to the Reconstruction governments in the South after the Civil War. The difference between the two is that the “carpetbaggers” were people who came from the North to work with the governments while “scalawags” were native Southerners.
Both of these terms are pejorative terms that come to us from a time when Reconstruction governments were seen in a very bad light. Historians once argued that these governments were dominated by African Americans who were unready for the task of governing (this was known as Negro rule) and by greedy whites. The carpetbaggers and scalawags were said to have joined the Reconstruction governments largely so that they could use their positions to get rich in corrupt ways.
Today, historians have largely gone away from these perceptions of Reconstruction, but the terms are still remembered and used to some degree.
"Scalawags" were Southerners who were sympathetic, or perceived as sympathetic, to Reconstruction, which not only involved repairing and repatriating the South after the Civil War but also involved making black people full citizens. This included giving them places in government and ownership of property (e.g., forty acres and a mule).
The origins of the term are unclear, though it developed in the 1840s, probably in response to the Whig party, which was sympathetic to the abolitionist cause. It is also important to note that the Republican party of that time developed out of the dissolved Whig Party. "Scalawag" describes a person or an animal considered to be worthless. Some scalawags were from the planter aristocracy, while others were Union soldiers from states like Kentucky or West Virginia. They were deemed "worthless" due to their unwillingness to support Southern values and heritage. Slavery and the eventual oppression of black citizens was integral to white Southern society, in addition to support of the rebel cause.
"Carpetbaggers" were Northerners who went South to profit off of its destitution after the war. As with the "scalawags," it is not clear, and also highly unlikely, that every Northerner or financier, usually from the North, went South in order to profit off of the region's misery. Indeed, there were some who were involved in financial schemes, but there were others who were interested in repairing the South and integrating black citizens.
Both terms illustrate Southern hostility toward the Reconstruction effort.