I think Pieter very clearly answers the primary question of "why does this map show them so close together" which is "that's the start points they withdrew out of range/line of sight in the evening." For the rest I offer the following answers:
There must have been times when they were in range but not attacking, during the daylight hours, right? Technically yes, but in reality not really. Troops not defending a specific location and not attacking (and this goes for troops from antiquity to today) will withdraw to a position of cover (like a trench or behind a hill where the enemy can't reach them with direct fire like small arms and cannon) and/or out of effective range of enemy fire. "Effective Range" is the important thing here. A rifled musket might have a theoretical range of 500 yards, but in reality nearly all fighting in the Civil War was done at under 200 yards, sometimes as close as 40-50 yards. The reason for this is twofold. One, troops are unlikely to shoot when they are unlikely to hit (the US Army realized this after WWI, which is why the 1908 Springfield has a range of over 1000 yards but the M1 Garand-onward was designed to hit out to only 300 yards). Civil War soldiers did almost no "live fire", with 10 rounds a year of practice shooting being a number I've read multiple places. (forgive me, I don't have a source on that to hand) Two, black powder creates a hellacious amount of powder smoke, so even if you start firing at 500 yards (a range where you are unlikely to hit) what you ARE likely to do is create a smoke bank in front of you which will make the enemy practically invisible as they get closer!
I mean, ammunition was certainly limited. So, we're there standing orders for what to do at a certain range? Sort of. Pickets were generally told to fire as soon as they saw the enemy so as to alert the main body (Hardee's Manual of Drill 1861 talks about skirmishers and much else on the subject). Skirmishers were given broader orders depending on the situation. For example they might be ordered to engage at maximum range to keep the enemy back, or they might be told to close on the enemy and direct their fire against specific targets. Troops in the main body (the traditional shoulder-to-shoulder we think of when we think ACW fighting) would generally be under strict orders NOT to fire unless ordered. This was to allow the officers to maintain control of the formation. Hardee's manual, Clauswitz, and many others of the time all state that once troops start firing they are hard to order to move again. Plus ammunition is scarce, and best employed in massed volleys. All of which meant that a normal soldier in the line was not supposed to shoot regardless of the location of the enemy until told to.
Would one side just suddenly begin firing at the other? Yes! Generally speaking in an infantry fight the defender would begin firing first, as it was the goal of the attacker to close with the bayonet and chase off (MUCH more likely than actually bayoneting folks, historically speaking) the defender. In an overall battle the attackers artillery would notionally begin the fighting, followed by both side's skirmishers ahead of the main infantry bodies, then the infantry.
Or was firing done while advancing towards the enemy? Yes, but the Europeans were generally horrified by this. (Justus Scheibert, the Prussian observer with Lee's army comes to mind) The accepted theory for attacking infantry with infantry in this period was to get as close as you could to your enemy (20-30 yards say), fire one volley with your muskets, then charge with the bayonet. The combined shock of a closely-delivered volley and the bayonet would drive off the enemy. However in the ACW troops would frequently end up in shooting matches until one side withdrew, which resulted in higher casualties. There were tactics for advancing by fire (Hardee again and other manuals) which involved buddy rushes (one man advances a bit, his buddy fires, then advances past man 1, etc. There was also methods of lines leapfrogging each other in a similar fashion (line one fires, line 2 advancs 10 yards ahead and fires, etc.). You see a lot of lines getting within 100-150 yards of each other and the attacker pushing forward as a mass while firing. It wasn't "supposed" to happen that way, but once a soldier stops to shoot it's hard to get him going again! So you get reports of regiments trying to advance, coming under fire, returning fire, then inching forward over a period of time until they either drive off the defender or retreat under the weight of enemy fire.