Depending on the work you can do stuff during third year. I was able to contribute to project I worked on with a couple of residents during M3, but most of my work was the kind of work that I could do at any time and only required a computer. I think doing standard lab work would be extremely difficult (though perhaps not totally impossible) during M3. If you want to do research, try and find clinical work that will lend itself to what will be a difficult and largely inflexible schedule.
You will have time during M4, but obviously there the problem becomes that you won't have too much time (i.e., a few months) to get work done. Depending on what you end up doing and how you use the time you could be extremely productive with just a few months. Many people do it. However, you should have a game plan and start working on connections before you actually start M4 so that when your schedule does open up you're ready to go.