renaming an image automatically everywhere else (posts and pages)

I did the same thing few days back. I took the post slug as image name for SEO purpose. I created a function to create/move images to a particular folder depending on the slug and input image url.

Here is look of my function-

function tb_get_image($image_ext_url,$slug,$upload_folder="",$title=""){
  $uri =  WP_CONTENT_DIR."/uploads/".$upload_folder;
  $folder =  WP_CONTENT_URL."/uploads/".$upload_folder;  

  if(!file_exists($uri)){
     $oldmask = umask(0);
     if(!mkdir ($uri, 0755)){
        $uri =  WP_CONTENT_DIR."/uploads/";
        $folder =  WP_CONTENT_URL."/uploads/";   
      }
  }


  $localimage = $uri.$slug.".jpg"; ## Use PHP_PATHINFO to get extension.
  $image = $folder.$slug.".jpg"; ## Use PHP_PATHINFO to get extension.

....

More code to rename and move/copy the image...
....
}

Hope this guide is enough to get you in right direction.