If we neglect the effect of dehydration and BM, then is weight gain a one variable function of calorie intake minus calorie consumption? If yes, how many grams one would gain for excessive 1000 calories? If no, what other factors are involved?
[I]s weight gain a one variable function of calorie intake minus calorie consumption?
Yes. It stands to reason because why else is the recommended daily calorie intake always talked about in nutritional information labels? Note, however, that as stipulated in the NHS link,
These values can vary depending on age, metabolism and levels of physical activity, among other things.
Calories not 'burnt' by the body's metabolism is stored as fat.
[H]ow many grams one would gain for excessive 1000 calories?
There are no definitive answers to this question as again, it seems to work out differently from person to person due to the components of intake and expenditure.
A link provided by @paparazzo states that with fat working out to be about 3500 calories per pound,
Some of the studies state that body fat tissue contains only 72% fat. Different types of body fat may also contain varying amounts of fat.
BOTTOM LINE:A pound of body fat may contain anywhere between 3,436 and 3,752 calories, roughly estimated.
The bottom line on this question
Calories not 'burnt' by the body's metabolism is stored as fat. If you are overweight you need to reduce your calorie intake and/or increase your exercise levels.
If you are underweight it is not straight forward as you need to have your weight gain managed.
There are many possible medical reasons for being underweight. Speak to your doctor because before trying to put on weight, you need to know that it is safe to do so.