Opto-Isolator For Volume Control?
Wait - You want a digital volume control that is controlled by a PWM output?  As in, you send the Arduino a command over the UART, or flip some switches to a binary value, and tell it to set the volume to 11? Then, your optoisolator applies a voltage/current somewhere in your output circuit?  We'd need a lot more info on what kind of output amplifier you're using.  It would probably be much easier to simply modify your PWM.  If you increase the maximum value, or decrease the input value, you can turn the volume down entirely in software.  

If you must, you can still use the analogWrite() function to control your PWM.  Try something like(pseudocode):

  //File scope variable to set the volume.  
  static uint8_t volume = 0;   

 void set_volume(uint8_t new_volume) {  
    if (new_volume &lt; 8)   // Would result in a volume of 0 
       volume = new_volume;  
 } 

 /** Divide by 2^volume:   
  *  0 = loudest,  
  *  1 = half as loud,    
  *  2 = 1/4 as loud,  
  *  3 = 1/8 as loud, etc.   
  */ 
 inline uint8_t adjust_volume(uint8_t signal) {  
    return (uint8_t) signal &gt;&gt; volume;  
 }  

 //Identical ISRs for each of the tactile switches  
 ISR(PCINT0_vect) {      
   setVolume(read(PORTC))  //Or however you get your digital volume signal  
}  

void main(void)  {  
   char *sound_buffer;  

   while(*sound_buffer)  
      analogWrite(adjust_volume(*sound_buffer++));  
}    


If you want to do a volume control with an optoisolated input, then yes, that's quite possible.  Assuming your input device is a pot, your options are a logical, frequency (rather than pulse width) modulated signal, which you can get from a voltage to frequency converter like the LM231 (there are many other options), or from an op-amp circuit with an RC oscillator.  Feed the output into any digital optoisolator, and you should be able to read the frequency on a digital input pin, and modify your speaker output PWM maximum value or modulate your input values accordingly.

Alternatively, you can use a photovoltaic output optoisolator, which outputs an analog voltage (or current) based on the input current.  Be careful of linearity issues when working with these circuits.  You don't really want a linear volume control (You want something closer to logarithmic, or you can go all-out and implement an equal loudness contour,) however, you don't want a digital switch.  The Vishay IL300 is an example of a linear phototransistor.

EDIT: I mentioned the AVR335 app note in a recent question about programmable greeting cards with audio.  That would be a good resource for your question as well.