Question: If I've a big sprite png image with 40x40 icons. How I can convert it to separate images for each icon with photoshop or gimp?

As the sprite is quite big I would prefer and automated method.

Answer: 
Okay, if you don't have too many sprites then this shouldn't take too long. It's not automated, but if that's what you're looking for let me know and I can help you with a script to do it (although at that point this begins to fall out of the bounds of Graphic Design) 

1. Setup your sprite grid in the Photoshop preferences: 40px x 40px with 1 subdivision.
2. ![enter image description here](https://i.stack.imgur.com/8SHox.png)
3. Make sure the grid is showing (View -> Show -> Grid) and snapping is on (View -> Snap To -> Grid)
4. If the rulers aren't showing around your document, press **Cmd (Ctrl) + R** to show them.
5. Click on the left side ruler and drag onto your document to make vertical guides. Line up the guides with your grid. Do the same horizontally from the top ruler. You can hide the grid now with **Cmd (Ctrl) + "**
6. ![enter image description here](https://i.stack.imgur.com/zpuJX.png)
7. Select the `Slice Tool` and press `Slices from Guides`
8. ![enter image description here](https://i.stack.imgur.com/NbOW8.png)
9. File -> Save For Web & Devices
10. Save Images Only

Another way to do this is to select the slice tool and create one big slice around the entire image. Then, with the slice tool still selected, right click on the slice and click on "divide slice". You will have several options for how to divide the slice both horizontally and vertically. You can divide it evenly in a certain number of slices or you can specify a pixel size.
Because `"the sprite is quite big"`, an excellent `"automated method"` is imagemagick. I know it is not Gimp or Photoshop but with large files and automation, it is by far easier to use imagemagick. You can automate this with simple Cron -one-liner, `$ crontab -e` but ask more about it in Stackoverflow. Anyway here the command:

> 
> $ convert your\_grid.png -crop 100x100 out%d.png
> 
> 
> 

getting new icons, `$ sudo apt-get install imagemagick` in Ubuntu. You can thank RJ for this -- welcome to the `##imagemagick` -irc channel in Freenode if you need help.