How can I integrate (optional) membership sign-up on a CiviEvent registration form?
There's an extension my colleague built for a client of ours that handles this: https://github.com/aghstrategies/com.aghstrategies.eventmembershipsignup

It should work for you. Unfortunately, we just haven't had the time to get it documented as much as I'd like (or to list it in the extensions directory). If you end up implementing this, please drop me a note at andrew -at- aghstrategies.com. I'd love to hear what suggestions you have, since it is on my to-do list to get it listed and write the documentation needed.