Each time you upload an image, store the image in a separate table, with one column of the time at which the image is uploaded; and another column to indicate whether the image is attached to a post. You may use postid for this column.
When an image is auto uploaded, you can populate a hidden input field to store the auto ID of the image, and forward it to the post creation handler. The newly created post will have an ID. Save this in the postid column in the image. Now your image filename is using the imageid, not postid, but it's okay. If you really want to change the image name after the post name, upload the original image as img_###.png; then rename it to *.png, where ### is the image ID, and * is the post id. The img_ prefix is necessary to avoid name conflict. Again, this is not necessary. Image ID is just fine.
Finally you can set up a cron job to delete the image files and records that are uploaded a while ago but without a post ID. This will purge all the auto uploaded images without a submitted form.
You do have to take care of image upload racing condition. What if your image is still being uploaded, and someone clicks on the form post button already?