It appears you have the right idea. Adjustment from a valid US non-immigrant status through an I-526 approval is possible. Retaining qualified US immigration counsel will help you with the process.
While you and your spouse are maintaining either F-1 or H1B status you can file your I-526 petition, obtain approval,and then file your application for conditional permanent resident while you are in the U.S