i did something simliar last year and have been very happy: bought a pre-built lamp-housing, a smart charger and built my own NiMh battery pack.
lamp: 20W spot - about $30 with bulb
5x size D 1.2V NIMH 7000mAh batteries = 6V and 7Ah
P = I x V
so (Current) I = P/V = 20W/6V = 3.33A (under ideal conditions)
with Capacity=7Ah, Time = Capacity/Current = 7Ah/3.3A = 2.1 hours = 2 hours, 6 minutes running time
as NiMH batteries are relatively light (not as light as Lithiom Ion) - it's not bad - i through the battery pack in my backpack and built a cable to the lamp which is mounted on my helmet.
i bought a good charger for about $45, batteries were like $70 i think, so all in all it was a little under $150 - cheap compared to a Nightrider or the new Cateye or the other high-power systems (yes, you can get a 1hr system for like $100)
i also have a 5W lamp/bulb that i hooked up to give a longer running time, but i rarely use it as most of my night rides are either 1-2 hour solo rides or group rides of 2-3 hours where i can turn it off for a few minutes and have not yet run out of light (2 weeks ago i hit around 2:05 and expected it to go out, but it did not) --- i may change it to a 10W bulb, so i can choose between 10W, 20W or 30W...
buying a pre-built lamp is a decent idea as it is important to a) dissapate heat effictively so you don't melt anything, b) keep water out, c) not have any vibration --- and for $20 to $30 a pre-built is worth it in my eyes unless you just want the satisfaction of building it all for yourself.
my next step (if i ever get time) will be to add some white LEDs so i can switch to "save power, but be seen" mode to increase my battery time.
P.S. yes, 1A = 1000mA --- with what you listed above with 12 1.2V 4000mAh batteries, you have 12V at 4Ah, so for 20W you need 20W/12V = 1.67A ---> time = Capactiy/Current = 4Ah/1.67A = 2.4 hours = 2 hours, 24 minutes
*--- note this is the ideal time which is greatly reduced if the batteries are COLD and the battery capacity also reduces with time (Lead Acid much more than NiMh) --- so try putting the batteries in a backpack if you ride in cold temps (cold = less than 40F)
** PPS sorry i studied electrical engineering so hopefully i didn't use too many "unknown" terms here - i tried to explain abbreviations