Assuming the mask dataset has each ROI marked with a different integer, you could do something like (using csh syntax)
3dhistog -omit 0 -unq U.1D maskdataset+tlrc > /dev/null
foreach uuu ( `1dcat U.1D` )
3dcalc -a maskdataset+tlrc -expr "equals(a,$uuu)" -prefix maskdataset.$uuu
end
\rm -f U.1D
For an ROI labeled with "3" (e.g.), you would get a dataset named maskdataset.3+tlrc whose values are 1 at each voxel where the input was 3, and whose values are 0 at all other voxels. If you with to preserve the input value, change the expression to "a*equals(a,$uuu)".
To become a Jedi AFNI Master, important it is to learn shell scripting.