Interesting situation, there are tremendous ramifications in every move you make, so I suggest you hire a good immigration attorney like Rajiv Khanna who can guide you along the right path.
As Wik mentioned, everything depends on why your AOS was denied. Now if you got married BEFORE the denial, you are still okay, but if it is AFTER the denial, you will have to prove that this marriage is not a sham or an immigration fraud.
You might still have to leave the country before your wife can sponsor your visa as spouse of American Citizen.