Actually, you can do this this 3 days in advance of your arrival:
Inicio
Edit: Forgot to mention that on the customs form, if you are flying into Cozumel, you have to select Cancun in the first box and then Cozumel in the checkpoint box. Why? Who knows!
For immigration forms, you can do those 30 days before your arrival:
Instituto Nacional de Migración - Forma Migratoria Múltiple
Way more convenient... particularly when your airline doesn't have the rights forms and everyone is standing in line while also trying to fill them out
Edit2: Forgot to also mention that these pages are available in both Spanish and English.