|At the time of this writing, ESRI has not "certified" the use of SE 5.x with ArcIMS 4.0.1. So if you are using ArcIMS 4.0.1 and you wish to use a version of ServletExec which ESRI officially certifies, then you should use SE 4.2 or SE 4.1.1. (NOTE: SE 5.0 will be offically certified by ESRI for use with ArcIMS 9.0)
However, if you choose to use SE 5.x ISAPI or NSAPI (in-process),
it is very likely that it would work just fine for you with ArcIMS 4.0.1. The ArcIMS Servlet Connector is the ESRI component which runs inside of ServletExec and which "connects" SE to ArcIMS. The ArcIMS Servlet Connector is basically just a servlet. Any servlet that runs inside of SE 4.x should run just fine inside of SE 5.x.
The biggest concern is if you wish to use ServletExec 5.x AS (out-of-process) instead of ISAPI or NSAPI (in-process).
If you do choose to try this combination, then the ArcIMS Servlet Connector should still work just fine, but you should not run the ArcIMS 4.0.1 Post Installer to set it up for you. This is because that version of the Post Installer was designed to run against SE 4.x and it will try to edit your web server's configuration files for you (servletexec.properties, obj.conf, httpd.conf), and the edits won't be correct for SE 5.x. Instead you should manually setup your ArcIMS Servlet Connector for use by SE 5.x.