With the pad plugged in type: ls /dev/input/ (this list the assigned device numbers of joysticks/gamepads)
Note the number after js
Here is my retroarch.cfg setup for a 360 pad: https://www.petrockblock.com/wp-content/uploads/2014/02/retroarch_xbox360pad.zip
You need to edit it and change input_player1_joypad_index = to the number noted above.
Place it in /opt/retropie/configs/all/
To test buttons and make adjustments:
sudo apt-get install joystick
jstest /dev/input/js*
(replace * with js number as above)